diff --git a/src/main/java/com/fjy/spring/controller/RegisterController.java b/src/main/java/com/fjy/spring/controller/RegisterController.java index 4a14e78..9c7eaf4 100644 --- a/src/main/java/com/fjy/spring/controller/RegisterController.java +++ b/src/main/java/com/fjy/spring/controller/RegisterController.java @@ -1,15 +1,20 @@ package com.fjy.spring.controller; +import com.fjy.spring.domain.TbStudentlist; import com.fjy.spring.domain.TbUser; import com.fjy.spring.enums.ResultEnum; import com.fjy.spring.exception.UserException; import com.fjy.spring.properties.ServerProperties; +import com.fjy.spring.service.StudentService; import com.fjy.spring.service.UserService; import com.fjy.spring.untils.CodingUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -22,6 +27,9 @@ public class RegisterController { @Autowired private UserService userService; + @Autowired + private StudentService studentService; + @Autowired private ServerProperties serverProperties; @@ -45,4 +53,23 @@ public class RegisterController { throw new UserException(ResultEnum.UNKOWN_ERROR); } + @GetMapping("/CheckStudentNo") + @ResponseBody + public boolean doCheckStudentNo(@RequestParam(value = "studentno") String studentno){ + TbStudentlist studentlist = studentService.findStudentByNo(studentno); + if (studentlist!=null) + return true; + return false; + } + + @GetMapping("/CheckStudent") + @ResponseBody + public boolean doCheckStudent(@RequestParam(value = "studentno") String studentno, + @RequestParam(value = "realname") String realname){ + TbStudentlist studentlist = studentService.findByColstudentnoAndColrealname(studentno,realname); + if (studentlist!=null) + return true; + return false; + } + } diff --git a/src/main/java/com/fjy/spring/repository/TbStudentListRepository.java b/src/main/java/com/fjy/spring/repository/TbStudentListRepository.java new file mode 100644 index 0000000..93e84d6 --- /dev/null +++ b/src/main/java/com/fjy/spring/repository/TbStudentListRepository.java @@ -0,0 +1,11 @@ +package com.fjy.spring.repository; + +import com.fjy.spring.domain.TbStudentlist; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TbStudentListRepository extends JpaRepository { + + public TbStudentlist findByColstudentno(String colstudentno); + + public TbStudentlist findByColstudentnoAndColrealname(String colstudentno,String colrealname); +} diff --git a/src/main/java/com/fjy/spring/service/StudentService.java b/src/main/java/com/fjy/spring/service/StudentService.java index b4f22b4..04c827c 100644 --- a/src/main/java/com/fjy/spring/service/StudentService.java +++ b/src/main/java/com/fjy/spring/service/StudentService.java @@ -1,7 +1,9 @@ package com.fjy.spring.service; import com.fjy.spring.domain.TbStudent; +import com.fjy.spring.domain.TbStudentlist; import com.fjy.spring.domain.TbUser; +import com.fjy.spring.repository.TbStudentListRepository; import com.fjy.spring.repository.TbStudentRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -13,4 +15,15 @@ public class StudentService { @Autowired private TbStudentRepository tbStudentRepository; + @Autowired + private TbStudentListRepository tbStudentListRepository; + + public TbStudentlist findStudentByNo(String studentno){ + return tbStudentListRepository.findByColstudentno(studentno); + } + + public TbStudentlist findByColstudentnoAndColrealname(String studentno,String realname){ + return tbStudentListRepository.findByColstudentnoAndColrealname(studentno,realname); + } + } diff --git a/src/main/resources/static/js/LoginStyle.js b/src/main/resources/static/js/LoginStyle.js index 1b390ab..432e034 100644 --- a/src/main/resources/static/js/LoginStyle.js +++ b/src/main/resources/static/js/LoginStyle.js @@ -3,22 +3,57 @@ var Main = { var checkName = (rule, value, callback) => { if (!value) { return callback(new Error('用户名不能为空')); - }else { + } else { callback() } }; var checkNo = (rule, value, callback) => { if (!value) { return callback(new Error('学号不能为空')); - }else { - callback() + } else { + //判断是否为指定班级的合法用户 + axios.get(getRootPath_web() + '/CheckStudentNo', { + params: { + studentno: value + } + }) + .then(function (response) { + console.log(response.data); + if (response.data === true) { + callback() + } else { + return callback(new Error('学号非法')); + } + }) + .catch(function (error) { + console.log(error); + this.errorNotify(error.message); + }); } }; var checkRealName = (rule, value, callback) => { if (!value) { return callback(new Error('真实姓名不能为空')); - }else { - callback() + } else { + //判断用户名与学号是否匹配 + axios.get(getRootPath_web() + '/CheckStudent', { + params: { + realname: value, + studentno: this.ruleForm2.colstudentno + } + }) + .then(function (response) { + console.log(response.data); + if (response.data === false) { + return callback(new Error('姓名与学号不匹配')); + } else { + callback() + } + }) + .catch(function (error) { + console.log(error); + this.errorNotify(error.message); + }); } }; var validatePass = (rule, value, callback) => { @@ -44,17 +79,17 @@ var Main = { ruleForm2: { colname: '', colpassword: '', - checkPass:'', + checkPass: '', colstudentno: '', colrealname: '', colemail: '' }, rules2: { colpassword: [ - {required: true,validator: validatePass, trigger: 'blur'} + {required: true, validator: validatePass, trigger: 'blur'} ], checkPass: [ - {required: true,validator: validatePass2, trigger: 'blur'} + {required: true, validator: validatePass2, trigger: 'blur'} ], colstudentno: [ { @@ -71,13 +106,19 @@ var Main = { } ], colname: [ - {required: true,validator: checkName, trigger: 'blur'} + {required: true, validator: checkName, trigger: 'blur'} ], }, - activeName:'login', + activeName: 'login', }; }, methods: { + errorNotify(content) { + this.$notify.error({ + title: '错误', + message: content + }) + }, submitForm(formName) { this.$refs[formName].validate((valid) => { if (valid) { diff --git a/src/test/java/com/fjy/spring/controller/RegisterControllerTest.java b/src/test/java/com/fjy/spring/controller/RegisterControllerTest.java index ecb3ca5..b76d99a 100644 --- a/src/test/java/com/fjy/spring/controller/RegisterControllerTest.java +++ b/src/test/java/com/fjy/spring/controller/RegisterControllerTest.java @@ -35,4 +35,30 @@ public class RegisterControllerTest { " \"data\": null\n" + "}")); } + + @Test + public void doCheckStudentNo()throws Exception { + //测试非法学号检查 + mvc.perform(MockMvcRequestBuilders.post("/CheckStudentNo") + .param("studentno","0003")) + .andExpect(MockMvcResultMatchers.content().string("false")); + //测试合法学号检查 + mvc.perform(MockMvcRequestBuilders.post("/CheckStudentNo") + .param("studentno","15251101238")) + .andExpect(MockMvcResultMatchers.content().string("true")); + } + + @Test + public void doCheckStudent()throws Exception { + //测试学号与姓名不匹配 + mvc.perform(MockMvcRequestBuilders.post("/CheckStudent") + .param("studentno","15251101238") + .param("realname","符嘉")) + .andExpect(MockMvcResultMatchers.content().string("false")); + //测试学号与姓名匹配 + mvc.perform(MockMvcRequestBuilders.post("/CheckStudent") + .param("studentno","15251101238") + .param("realname","符嘉阳")) + .andExpect(MockMvcResultMatchers.content().string("true")); + } } \ No newline at end of file