wangwei 7 anos atrás
pai
commit
ac777490c8

+ 26 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/StudentController.java

@@ -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();
+	}
+
 }

+ 0 - 18
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/UserController.java

@@ -351,24 +351,6 @@ public class UserController extends ControllerSupport {
 		return new ResponseEntity(HttpStatus.OK);
 	}
 
-	@ApiOperation(value = "修改用户密码", notes = "修改密码")
-	@PutMapping("/stu-password")
-	public ResponseEntity stuPassword(@RequestParam("oldPassword") String oldPassword,
-			@RequestParam("newPassword") String newPassword, HttpServletRequest request) {
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-		if (StringUtils.isEmpty(oldPassword) || StringUtils.isEmpty(newPassword)) {
-			return new ResponseEntity(new ErrorMsg("原密码不正确"), HttpStatus.BAD_REQUEST);
-		} else {
-			Long userId = accessUser.getUserId();
-			UserEntity user = userRepo.findOne(userId);
-			if (!oldPassword.equals(user.getPassword())) {
-				return new ResponseEntity(new ErrorMsg("原密码不正确"), HttpStatus.BAD_REQUEST);
-			}
-			userRepo.updatePasswordById(userId, newPassword);
-			return new ResponseEntity(HttpStatus.OK);
-		}
-	}
-
 	@ApiOperation(value = "按id删除用户", notes = "删除")
 	@DeleteMapping("/{ids}")
 	@Uac(roles = {RoleMeta.SUPER_ADMIN}, policy = UacPolicy.IN)