|
@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
@@ -207,4 +208,29 @@ public class StudentController extends ControllerSupport {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "修改用户密码", notes = "修改密码")
|
|
|
+ @PutMapping("password")
|
|
|
+ public Long stuPassword(@RequestParam("oldPassword") String oldPassword,
|
|
|
+ @RequestParam("newPassword") String newPassword, HttpServletRequest request) {
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ if (StringUtils.isEmpty(oldPassword)) {
|
|
|
+ throw new StatusException("B-450110", "旧密码为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(newPassword)) {
|
|
|
+ throw new StatusException("B-450111", "新密码为空");
|
|
|
+ }
|
|
|
+ if (newPassword.matches("[a-zA-Z0-9]{6,18}")) {
|
|
|
+ throw new StatusException("B-450111", "密码必须为6至18位字母和数字组合");
|
|
|
+ }
|
|
|
+
|
|
|
+ Student s = studentRepo.findOne(accessUser.getStudentId());
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(s.getPassword()) && !s.getPassword().equals(oldPassword)) {
|
|
|
+ throw new StatusException("B-450111", "当前密码错误");
|
|
|
+ }
|
|
|
+ s.setPassword(newPassword);
|
|
|
+ studentRepo.save(s);
|
|
|
+ return s.getId();
|
|
|
+ }
|
|
|
+
|
|
|
}
|