diff --git a/web/src/main/java/com/ibeetl/jlw/dao/StudentDao.java b/web/src/main/java/com/ibeetl/jlw/dao/StudentDao.java index 76f68bd5..9a03da5c 100644 --- a/web/src/main/java/com/ibeetl/jlw/dao/StudentDao.java +++ b/web/src/main/java/com/ibeetl/jlw/dao/StudentDao.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import com.ibeetl.jlw.entity.CourseInfo; import com.ibeetl.jlw.entity.Student; import com.ibeetl.jlw.entity.StudentExtendSchoolInfo; +import com.ibeetl.jlw.entity.dto.StudentEditPasswordDTO; import com.ibeetl.jlw.web.query.StudentQuery; import org.beetl.sql.core.engine.PageQuery; import org.beetl.sql.mapper.BaseMapper; @@ -62,4 +63,12 @@ public interface StudentDao extends BaseMapper{ * @return */ List getStudentExtendSchoolInfoListByUserIds(String userIds); + + + /** + * 学生端-修改密码,数据库验证 + * @param dto + * @return + */ + Student getStudentByStudentEditPasswordDTO(StudentEditPasswordDTO dto); } \ No newline at end of file diff --git a/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentEditPasswordDTO.java b/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentEditPasswordDTO.java new file mode 100644 index 00000000..3b9da71b --- /dev/null +++ b/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentEditPasswordDTO.java @@ -0,0 +1,56 @@ +package com.ibeetl.jlw.entity.dto; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + *

+ * 学生端-注册实体 + *

+ * + * @author mlx + * @date 2022/11/20 + * @modified + */ +@Data +public class StudentEditPasswordDTO { + + // 验证院校的授权码 + /** + * 院校ID + */ + @NotNull(message = "院校不能为空!") + private Long universitiesCollegesId; + /** + * 院校授权码 + */ + @NotEmpty(message = "院校授权码不能为空!") + private String universitiesCollegesAuthCode; + + + /** + * 学生姓名 + */ + @NotEmpty(message = "院校不能为空!") + private String studentName; + /** + * 学生编号 + */ + @NotEmpty(message = "学生编号不能为空!") + private String studentSn; + + /** + * 原密码 + */ + @NotEmpty(message = "原密码不能为空!") + private String oldPwd; + + /** + * 新密码 + */ + @NotEmpty(message = "新密码不能为空!") + private String newPwd; + +} diff --git a/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentRegisterDTO.java b/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentRegisterDTO.java index f40e865b..1554c856 100644 --- a/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentRegisterDTO.java +++ b/web/src/main/java/com/ibeetl/jlw/entity/dto/StudentRegisterDTO.java @@ -19,21 +19,33 @@ import javax.validation.constraints.NotNull; @Data public class StudentRegisterDTO { + // 验证院校的授权码 /** * 院校ID */ @NotNull(message = "院校不能为空!") private Long universitiesCollegesId; + /** + * 院校授权码 + */ + @NotEmpty(message = "院校授权码不能为空!") + private String universitiesCollegesAuthCode; + + + // 其他信息,暂时没用到,可传可不传 /** * 院系ID */ - @NotNull(message = "院校不能为空!") + @NotNull(message = "院系不能为空!") private Long universityFacultyId; /** * 专业ID */ @NotNull(message = "专业不能为空!") private Long universitySystemId; + + + // 学生信息 要求和Student一致,用于Copy属性 /** * 班级ID */ @@ -61,9 +73,5 @@ public class StudentRegisterDTO { @Email @NotEmpty(message = "邮箱不能为空!") private String studentEmail; - /** - * 院校授权码 - */ - @NotEmpty(message = "院校授权码不能为空!") - private String universitiesCollegesAuthCode; + } diff --git a/web/src/main/java/com/ibeetl/jlw/service/UniversitiesCollegesService.java b/web/src/main/java/com/ibeetl/jlw/service/UniversitiesCollegesService.java index ead48e64..5c6c3d64 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/UniversitiesCollegesService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/UniversitiesCollegesService.java @@ -228,4 +228,10 @@ public class UniversitiesCollegesService extends CoreBaseService 0; } + + public void verifyUniAuthCodeThrows(@NotNull(message="院校ID不能为空!") Long universitiesCollegesId, + @NotEmpty(message="院校授权码不能为空!") String universitiesCollegesAuthCode) { + boolean verifyUniAuthCode = verifyUniAuthCode(universitiesCollegesId, universitiesCollegesAuthCode); + Assert.isTrue(verifyUniAuthCode, "院校授权码,验证失败!"); + } } diff --git a/web/src/main/java/com/ibeetl/jlw/service/api/student/ApiStudentService.java b/web/src/main/java/com/ibeetl/jlw/service/api/student/ApiStudentService.java index 695af3c3..0a6d59dd 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/api/student/ApiStudentService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/api/student/ApiStudentService.java @@ -2,11 +2,14 @@ package com.ibeetl.jlw.service.api.student; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.lang.Assert; -import com.ibeetl.admin.core.service.CorePlatformService; +import com.ibeetl.admin.core.conf.PasswordConfig; +import com.ibeetl.admin.core.service.CoreUserService; +import com.ibeetl.jlw.dao.StudentDao; import com.ibeetl.jlw.dao.TeacherOpenCourseMergeStudentDao; import com.ibeetl.jlw.entity.*; import com.ibeetl.jlw.entity.api.CurrentUserInfo; import com.ibeetl.jlw.entity.api.student.StudentIndexData; +import com.ibeetl.jlw.entity.dto.StudentEditPasswordDTO; import com.ibeetl.jlw.entity.dto.StudentRegisterDTO; import com.ibeetl.jlw.service.*; import com.ibeetl.jlw.web.query.TeacherOpenCourseMergeStudentQuery; @@ -34,10 +37,12 @@ public class ApiStudentService { @Autowired private IndexBaseService indexBaseService; @Autowired private TeacherOpenCourseNoticeService teacherOpenCourseNoticeService; @Autowired private StudentService studentService; + @Autowired private StudentDao studentDao; @Autowired private ResourcesApplicationService resourcesApplicationService; @Autowired private TeacherOpenCourseMergeStudentDao teacherOpenCourseMergeStudentDao; @Autowired private UniversitiesCollegesService universitiesCollegesService; - @Autowired private CorePlatformService corePlatformService; + @Autowired private PasswordConfig.PasswordEncryptService passwordEncryptService; + @Autowired private CoreUserService coreUserService; /** * 教师端-首页数据 @@ -89,10 +94,44 @@ public class ApiStudentService { final Long universitiesCollegesId = dto.getUniversitiesCollegesId(); // 传入的院校授权码 final String universitiesCollegesAuthCode = dto.getUniversitiesCollegesAuthCode(); - boolean verifyUniAuthCode = universitiesCollegesService.verifyUniAuthCode(universitiesCollegesId, universitiesCollegesAuthCode); - Assert.isTrue(verifyUniAuthCode, "院校授权码,验证失败!"); + universitiesCollegesService.verifyUniAuthCodeThrows(universitiesCollegesId, universitiesCollegesAuthCode); // 以上验证都通过的话,就可以注册用户 studentService.add(BeanUtil.copyProperties(dto, Student.class)); } + + /** + * 学生端-独有的修改密码 + * @param dto + */ + public void editPwd(@NotNull(message = "修改密码信息不能为空!") StudentEditPasswordDTO dto) { + + // 密码遵循加密算法 + dto.setNewPwd(passwordEncryptService.password(dto.getNewPwd())); + dto.setOldPwd(passwordEncryptService.password(dto.getOldPwd())); + + // 传入的院校ID + final Long universitiesCollegesId = dto.getUniversitiesCollegesId(); + // 传入的院校授权码 + final String universitiesCollegesAuthCode = dto.getUniversitiesCollegesAuthCode(); + universitiesCollegesService.verifyUniAuthCodeThrows(universitiesCollegesId, universitiesCollegesAuthCode); + + { + Student entity = new Student(); + entity.setStudentStatus(1); + entity.setStudentSn(dto.getStudentSn()); + Assert.isTrue(studentDao.templateCount(entity) > 0, "学生编号不存在!"); + + entity.setStudentSn(null); + entity.setStudentName(dto.getStudentName()); + Assert.isTrue(studentDao.templateCount(entity) > 0, "学生姓名不存在!"); + } + + Student studentInfo = studentDao.getStudentByStudentEditPasswordDTO(dto); + Assert.notNull(studentInfo, "原始密码错误!"); + + // 根据旧密码修改新密码 + Boolean updateSuccess = coreUserService.editPwdByOld(dto.getOldPwd(), dto.getNewPwd(), studentInfo.getUserId()); + Assert.isTrue(updateSuccess, "密码修改失败!"); + } } diff --git a/web/src/main/java/com/ibeetl/jlw/web/api/student/ApiStudentController.java b/web/src/main/java/com/ibeetl/jlw/web/api/student/ApiStudentController.java index 4b3301a4..b3520484 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/api/student/ApiStudentController.java +++ b/web/src/main/java/com/ibeetl/jlw/web/api/student/ApiStudentController.java @@ -2,6 +2,7 @@ package com.ibeetl.jlw.web.api.student; import com.ibeetl.admin.core.web.JsonResult; import com.ibeetl.jlw.entity.api.student.StudentIndexData; +import com.ibeetl.jlw.entity.dto.StudentEditPasswordDTO; import com.ibeetl.jlw.entity.dto.StudentRegisterDTO; import com.ibeetl.jlw.service.api.student.ApiStudentService; import lombok.extern.slf4j.Slf4j; @@ -44,4 +45,17 @@ public class ApiStudentController { apiStudentService.register(dto); return JsonResult.success(); } + + /** + * 学生端-独有的修改密码 + * + * @date 2022/11/20 + * @return + */ + @PostMapping("editPwd.do") + public JsonResult editPwd(StudentEditPasswordDTO dto) { + apiStudentService.editPwd(dto); + return JsonResult.success(); + } + } diff --git a/web/src/main/resources/sql/jlw/student.md b/web/src/main/resources/sql/jlw/student.md index f399ee23..43ab4994 100644 --- a/web/src/main/resources/sql/jlw/student.md +++ b/web/src/main/resources/sql/jlw/student.md @@ -1409,3 +1409,22 @@ getStudentExtendSchoolInfoListByUserIds WHERE 1 = 1 AND FIND_IN_SET(t.user_id,#userIds#) + +getStudentByStudentEditPasswordDTO +=== +* 学生端-修改密码 验证信息 + + SELECT + t.* + FROM + student t + LEFT JOIN core_user ta ON ta.ID = t.user_id + WHERE + 1 = 1 + AND t.student_status = 1 + AND ta.STATE = 'S1' + AND ta.DEL_FLAG = 0 + AND t.student_name = #studentName# + AND t.student_sn = #studentSn# + AND ta.PASSWORD = #oldPwd# + \ No newline at end of file