Ver código fonte

update: 完善身份认证

weijin 5 anos atrás
pai
commit
4a616b19ec

BIN
.DS_Store


+ 115 - 104
seecoder-portal-common/src/main/java/cn/seecoder/seecoderportalcommon/vo/TeacherVO.java

@@ -1,104 +1,115 @@
-package cn.seecoder.seecoderportalcommon.vo;
-
-import org.springframework.data.annotation.CreatedDate;
-
-import java.time.OffsetDateTime;
-
-/**
- * @author kunduin
- */
-public class TeacherVO {
-    private Long id;
-
-    private String realName;
-
-    private String organization;
-
-    private String jobNumber;
-
-    private String certificate;
-
-    private UserVO userDetail;
-
-    private OffsetDateTime createdTime;
-
-    private TeacherState state;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public String getRealName() {
-        return realName;
-    }
-
-    public void setRealName(String realName) {
-        this.realName = realName;
-    }
-
-    public String getOrganization() {
-        return organization;
-    }
-
-    public void setOrganization(String organization) {
-        this.organization = organization;
-    }
-
-    public String getJobNumber() {
-        return jobNumber;
-    }
-
-    public void setJobNumber(String jobNumber) {
-        this.jobNumber = jobNumber;
-    }
-
-    public String getCertificate() {
-        return certificate;
-    }
-
-    public void setCertificate(String certificate) {
-        this.certificate = certificate;
-    }
-
-    public UserVO getUserDetail() {
-        return userDetail;
-    }
-
-    public void setUserDetail(UserVO userDetail) {
-        this.userDetail = userDetail;
-    }
-
-    public OffsetDateTime getCreatedTime() {
-        return createdTime;
-    }
-
-    public void setCreatedTime(OffsetDateTime createdTime) {
-        this.createdTime = createdTime;
-    }
-
-    public TeacherState getState() {
-        return state;
-    }
-
-    public void setState(TeacherState state) {
-        this.state = state;
-    }
-
-    @Override
-    public String toString() {
-        return "TeacherVO{" +
-                "id=" + id +
-                ", realName='" + realName + '\'' +
-                ", organization='" + organization + '\'' +
-                ", jobNumber='" + jobNumber + '\'' +
-                ", certificate='" + certificate + '\'' +
-                ", userDetail=" + userDetail +
-                ", createdTime=" + createdTime +
-                ", state=" + state +
-                '}';
-    }
-}
+package cn.seecoder.seecoderportalcommon.vo;
+
+import org.springframework.data.annotation.CreatedDate;
+
+import java.time.OffsetDateTime;
+
+/**
+ * @author kunduin
+ */
+public class TeacherVO {
+    private Long id;
+
+    private String realName;
+
+    private String organization;
+
+    private String jobNumber;
+
+    private String certificate;
+
+    private UserVO userDetail;
+
+    private OffsetDateTime createdTime;
+
+    private TeacherState state;
+
+    private UserRole role;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getRealName() {
+        return realName;
+    }
+
+    public void setRealName(String realName) {
+        this.realName = realName;
+    }
+
+    public String getOrganization() {
+        return organization;
+    }
+
+    public void setOrganization(String organization) {
+        this.organization = organization;
+    }
+
+    public String getJobNumber() {
+        return jobNumber;
+    }
+
+    public void setJobNumber(String jobNumber) {
+        this.jobNumber = jobNumber;
+    }
+
+    public String getCertificate() {
+        return certificate;
+    }
+
+    public void setCertificate(String certificate) {
+        this.certificate = certificate;
+    }
+
+    public UserVO getUserDetail() {
+        return userDetail;
+    }
+
+    public void setUserDetail(UserVO userDetail) {
+        this.userDetail = userDetail;
+    }
+
+    public OffsetDateTime getCreatedTime() {
+        return createdTime;
+    }
+
+    public void setCreatedTime(OffsetDateTime createdTime) {
+        this.createdTime = createdTime;
+    }
+
+    public TeacherState getState() {
+        return state;
+    }
+
+    public void setState(TeacherState state) {
+        this.state = state;
+    }
+
+    public UserRole getRole() {
+        return role;
+    }
+
+    public void setRole(UserRole role) {
+        this.role = role;
+    }
+
+    @Override
+    public String toString() {
+        return "TeacherVO{" +
+                "id=" + id +
+                ", realName='" + realName + '\'' +
+                ", organization='" + organization + '\'' +
+                ", jobNumber='" + jobNumber + '\'' +
+                ", certificate='" + certificate + '\'' +
+                ", userDetail=" + userDetail +
+                ", createdTime=" + createdTime +
+                ", state=" + state +
+                ", role=" + role +
+                '}';
+    }
+}

+ 49 - 39
seecoder-portal-common/src/main/java/cn/seecoder/seecoderportalcommon/vo/UserRole.java

@@ -1,39 +1,49 @@
-package cn.seecoder.seecoderportalcommon.vo;
-
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-
-/**
- * @author Kunduin
- */
-public enum UserRole {
-    /**
-     * 学生身份
-     */
-    STUDENT("STUDENT"),
-
-    /**
-     * 教师身份
-     */
-    TEACHER("TEACHER"),
-
-    /**
-     * 管理员身份
-     */
-    ADMIN("ADMIN");
-
-    private final String role;
-
-    UserRole(String role) {
-        this.role = role;
-    }
-
-    @Override
-    public String toString() {
-        return role;
-    }
-
-    public GrantedAuthority toAuthority() {
-        return new SimpleGrantedAuthority(role);
-    }
-}
+package cn.seecoder.seecoderportalcommon.vo;
+
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+
+/**
+ * @author Kunduin
+ */
+public enum UserRole {
+    /**
+     * 学生身份
+     */
+    STUDENT("STUDENT"),
+
+    /**
+     * 教师身份
+     */
+    TEACHER("TEACHER"),
+
+    /**
+     * 管理员身份
+     */
+    ADMIN("ADMIN"),
+
+    /**
+     * 职员身份
+     */
+    STAFF("STAFF"),
+
+    /**
+     * HR身份
+     */
+    HR("HR");
+
+    private final String role;
+
+    UserRole(String role) {
+        this.role = role;
+    }
+
+    @Override
+    public String toString() {
+        return role;
+    }
+
+    public GrantedAuthority toAuthority() {
+        return new SimpleGrantedAuthority(role);
+    }
+}

+ 134 - 121
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/domain/Teacher.java

@@ -1,121 +1,134 @@
-package cn.seecoder.seecoderportalserver.domain;
-
-import cn.seecoder.seecoderportalcommon.vo.TeacherState;
-import org.hibernate.annotations.CreationTimestamp;
-import org.springframework.data.annotation.CreatedDate;
-
-import javax.persistence.*;
-import java.time.OffsetDateTime;
-
-/**
- * @author Kunduin
- */
-@Entity(name = "teacher")
-@Table(name = "teacher")
-public class Teacher {
-    @Id
-    @GeneratedValue(strategy = GenerationType.AUTO)
-    private Long id;
-
-    @Column(length = 64, nullable = false)
-    private String realName;
-
-    @Column(length = 64, nullable = false)
-    private String organization = "南京大学";
-
-    @Column(length = 64, nullable = false)
-    private String jobNumber;
-
-    @Column(length = 512)
-    private String certificate = "";
-
-    @OneToOne(fetch = FetchType.EAGER)
-    @JoinColumn(name = "uid", nullable = false)
-    private User userDetail;
-
-    @Column(nullable = false)
-    @CreationTimestamp
-    private OffsetDateTime createdTime;
-
-    @Column(nullable = false)
-    @Enumerated(EnumType.STRING)
-    private TeacherState state = TeacherState.IDENTIFYING;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public String getRealName() {
-        return realName;
-    }
-
-    public void setRealName(String realName) {
-        this.realName = realName;
-    }
-
-    public String getOrganization() {
-        return organization;
-    }
-
-    public void setOrganization(String organization) {
-        this.organization = organization;
-    }
-
-    public String getJobNumber() {
-        return jobNumber;
-    }
-
-    public void setJobNumber(String jobNumber) {
-        this.jobNumber = jobNumber;
-    }
-
-    public String getCertificate() {
-        return certificate;
-    }
-
-    public void setCertificate(String certificate) {
-        this.certificate = certificate;
-    }
-
-    public User getUserDetail() {
-        return userDetail;
-    }
-
-    public void setUserDetail(User userDetail) {
-        this.userDetail = userDetail;
-    }
-
-    public OffsetDateTime getCreatedTime() {
-        return createdTime;
-    }
-
-    public void setCreatedTime(OffsetDateTime createdTime) {
-        this.createdTime = createdTime;
-    }
-
-    public TeacherState getState() {
-        return state;
-    }
-
-    public void setState(TeacherState state) {
-        this.state = state;
-    }
-
-    @Override
-    public String toString() {
-        return "Teacher{" +
-                "id=" + id +
-                ", realName='" + realName + '\'' +
-                ", organization='" + organization + '\'' +
-                ", jobNumber='" + jobNumber + '\'' +
-                ", certificate='" + certificate + '\'' +
-                ", userDetail=" + userDetail +
-                ", createdTime=" + createdTime +
-                ", state=" + state +
-                '}';
-    }
-}
+package cn.seecoder.seecoderportalserver.domain;
+
+import cn.seecoder.seecoderportalcommon.vo.TeacherState;
+import cn.seecoder.seecoderportalcommon.vo.UserRole;
+import org.hibernate.annotations.CreationTimestamp;
+import org.springframework.data.annotation.CreatedDate;
+
+import javax.persistence.*;
+import java.time.OffsetDateTime;
+
+/**
+ * @author Kunduin
+ */
+@Entity(name = "teacher")
+@Table(name = "teacher")
+public class Teacher {
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private Long id;
+
+    @Column(length = 64, nullable = false)
+    private String realName;
+
+    @Column(length = 64, nullable = false)
+    private String organization = "南京大学";
+
+    @Column(length = 64, nullable = false)
+    private String jobNumber;
+
+    @Column(length = 512)
+    private String certificate = "";
+
+    @OneToOne(fetch = FetchType.EAGER)
+    @JoinColumn(name = "uid", nullable = false)
+    private User userDetail;
+
+    @Column(nullable = false)
+    @CreationTimestamp
+    private OffsetDateTime createdTime;
+
+    @Column(nullable = false)
+    @Enumerated(EnumType.STRING)
+    private TeacherState state = TeacherState.IDENTIFYING;
+
+    @Column(nullable = false)
+    private UserRole role;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getRealName() {
+        return realName;
+    }
+
+    public void setRealName(String realName) {
+        this.realName = realName;
+    }
+
+    public String getOrganization() {
+        return organization;
+    }
+
+    public void setOrganization(String organization) {
+        this.organization = organization;
+    }
+
+    public String getJobNumber() {
+        return jobNumber;
+    }
+
+    public void setJobNumber(String jobNumber) {
+        this.jobNumber = jobNumber;
+    }
+
+    public String getCertificate() {
+        return certificate;
+    }
+
+    public void setCertificate(String certificate) {
+        this.certificate = certificate;
+    }
+
+    public User getUserDetail() {
+        return userDetail;
+    }
+
+    public void setUserDetail(User userDetail) {
+        this.userDetail = userDetail;
+    }
+
+    public OffsetDateTime getCreatedTime() {
+        return createdTime;
+    }
+
+    public void setCreatedTime(OffsetDateTime createdTime) {
+        this.createdTime = createdTime;
+    }
+
+    public TeacherState getState() {
+        return state;
+    }
+
+    public void setState(TeacherState state) {
+        this.state = state;
+    }
+
+    public UserRole getRole() {
+        return role;
+    }
+
+    public void setRole(UserRole role) {
+        this.role = role;
+    }
+
+    @Override
+    public String toString() {
+        return "Teacher{" +
+                "id=" + id +
+                ", realName='" + realName + '\'' +
+                ", organization='" + organization + '\'' +
+                ", jobNumber='" + jobNumber + '\'' +
+                ", certificate='" + certificate + '\'' +
+                ", userDetail=" + userDetail +
+                ", createdTime=" + createdTime +
+                ", state=" + state +
+                ", role=" + role +
+                '}';
+    }
+}

+ 84 - 84
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/AdminController.java

@@ -1,84 +1,84 @@
-package cn.seecoder.seecoderportalserver.web.rest;
-
-import cn.seecoder.seecoderportalcommon.vo.TeacherState;
-import cn.seecoder.seecoderportalcommon.vo.TeacherVO;
-import cn.seecoder.seecoderportalcommon.vo.UserRole;
-import cn.seecoder.seecoderportalcommon.vo.UserVO;
-import cn.seecoder.seecoderportalserver.mapper.UserMapper;
-import cn.seecoder.seecoderportalserver.service.TeacherService;
-import cn.seecoder.seecoderportalserver.service.UserService;
-import cn.seecoder.seecoderportalserver.utility.OkResponse;
-import cn.seecoder.seecoderportalcommon.vo.dto.UpdateUserByIdDTO;
-import cn.seecoder.seecoderportalcommon.vo.dto.UpdateUserValidDTO;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * @author kunduin
- */
-@RestController
-@RequestMapping("/api/admin")
-public class AdminController {
-
-    private final TeacherService teacherService;
-    private final UserService userService;
-    private final UserMapper userMapper;
-
-    public AdminController(TeacherService teacherService, UserService userService, UserMapper userMapper) {
-        this.teacherService = teacherService;
-        this.userService = userService;
-        this.userMapper = userMapper;
-    }
-
-    /**
-     * 获取待审批的用户列表
-     */
-    @GetMapping("/getApplication")
-    public OkResponse<List<TeacherVO>> getApplication() {
-        return OkResponse.of(teacherService.findAllByState(TeacherState.IDENTIFYING).stream()
-                .map(userMapper::teacherToTeacherVO)
-                .collect(Collectors.toList()));
-    }
-
-    /**
-     * 获取所有 ADMIN 权限的用户
-     */
-    @GetMapping("/getUsers")
-    public OkResponse<List<UserVO>> getUsers() {
-        return OkResponse.of(userService.findUserByRole(UserRole.ADMIN).stream()
-                .map(userMapper::userToUserVO)
-                .collect(Collectors.toList()));
-    }
-
-    /**
-     * 更新用户,改变其 valid 状态
-     */
-    @PostMapping("/updateUser")
-    public OkResponse<Boolean> updateUser(@RequestBody UpdateUserValidDTO updateUserValidDTO) {
-        userService.updateUserValid(updateUserValidDTO.getId(), updateUserValidDTO.getValid());
-        return OkResponse.of(true);
-    }
-
-    /**
-     * 使该【教师】通过审核
-     */
-    @PostMapping("/passApplication")
-    public OkResponse<TeacherVO> passApplication(@RequestBody UpdateUserByIdDTO idDTO) {
-        return OkResponse.of(userMapper.teacherToTeacherVO(
-                teacherService.updateState(idDTO.getId(), TeacherState.IDENTIFIED)
-        ));
-    }
-
-
-    /**
-     * 使该【教师】通过审核
-     */
-    @PostMapping("/rejectApplication")
-    public OkResponse<TeacherVO> rejectApplication(@RequestBody UpdateUserByIdDTO idDTO) {
-        return OkResponse.of(userMapper.teacherToTeacherVO(
-                teacherService.updateState(idDTO.getId(), TeacherState.REJECTED)
-        ));
-    }
-}
+package cn.seecoder.seecoderportalserver.web.rest;
+
+import cn.seecoder.seecoderportalcommon.vo.TeacherState;
+import cn.seecoder.seecoderportalcommon.vo.TeacherVO;
+import cn.seecoder.seecoderportalcommon.vo.UserRole;
+import cn.seecoder.seecoderportalcommon.vo.UserVO;
+import cn.seecoder.seecoderportalserver.mapper.UserMapper;
+import cn.seecoder.seecoderportalserver.service.TeacherService;
+import cn.seecoder.seecoderportalserver.service.UserService;
+import cn.seecoder.seecoderportalserver.utility.OkResponse;
+import cn.seecoder.seecoderportalcommon.vo.dto.UpdateUserByIdDTO;
+import cn.seecoder.seecoderportalcommon.vo.dto.UpdateUserValidDTO;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author kunduin
+ */
+@RestController
+@RequestMapping("/api/admin")
+public class AdminController {
+
+    private final TeacherService teacherService;
+    private final UserService userService;
+    private final UserMapper userMapper;
+
+    public AdminController(TeacherService teacherService, UserService userService, UserMapper userMapper) {
+        this.teacherService = teacherService;
+        this.userService = userService;
+        this.userMapper = userMapper;
+    }
+
+    /**
+     * 获取待审批的用户列表
+     */
+    @GetMapping("/getApplication")
+    public OkResponse<List<TeacherVO>> getApplication() {
+        return OkResponse.of(teacherService.findAllByState(TeacherState.IDENTIFYING).stream()
+                .map(userMapper::teacherToTeacherVO)
+                .collect(Collectors.toList()));
+    }
+
+    /**
+     * 获取所有 ADMIN 权限的用户
+     */
+    @GetMapping("/getUsers")
+    public OkResponse<List<UserVO>> getUsers() {
+        return OkResponse.of(userService.findUserByRole(UserRole.ADMIN).stream()
+                .map(userMapper::userToUserVO)
+                .collect(Collectors.toList()));
+    }
+
+    /**
+     * 更新用户,改变其 valid 状态
+     */
+    @PostMapping("/updateUser")
+    public OkResponse<Boolean> updateUser(@RequestBody UpdateUserValidDTO updateUserValidDTO) {
+        userService.updateUserValid(updateUserValidDTO.getId(), updateUserValidDTO.getValid());
+        return OkResponse.of(true);
+    }
+
+    /**
+     * 使该【教师】通过审核
+     */
+    @PostMapping("/passApplication")
+    public OkResponse<TeacherVO> passApplication(@RequestBody UpdateUserByIdDTO idDTO) {
+        return OkResponse.of(userMapper.teacherToTeacherVO(
+                teacherService.updateState(idDTO.getId(), TeacherState.IDENTIFIED)
+        ));
+    }
+
+
+    /**
+     * 使该【教师】通过审核
+     */
+    @PostMapping("/rejectApplication")
+    public OkResponse<TeacherVO> rejectApplication(@RequestBody UpdateUserByIdDTO idDTO) {
+        return OkResponse.of(userMapper.teacherToTeacherVO(
+                teacherService.updateState(idDTO.getId(), TeacherState.REJECTED)
+        ));
+    }
+}