WANG 6 жил өмнө
parent
commit
262bd06056

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

@@ -1,6 +1,7 @@
 package cn.com.qmth.examcloud.core.basic.api.controller;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -256,6 +257,37 @@ public class StudentController extends ControllerSupport {
 		}
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param newPassword
+	 * @param request
+	 * @return
+	 */
+	@ApiOperation(value = "修改学生密码", notes = "修改密码")
+	@PutMapping("password/direct")
+	public Long updateStudentPassword(@RequestParam("newPassword") String newPassword) {
+		User accessUser = getAccessUser();
+		if (StringUtils.isEmpty(newPassword)) {
+			throw new StatusException("B-450201", "新密码为空");
+		}
+
+		Date tokenCreationTime = accessUser.getTokenCreationTime();
+		if (System.currentTimeMillis() - tokenCreationTime.getTime() > 1000 * 60 * 5) {
+			throw new StatusException("B-450202", "密码必须是6至18位字母或数字");
+		}
+
+		if (!newPassword.matches("[a-zA-Z0-9]{6,18}")) {
+			throw new StatusException("B-450203", "密码必须是6至18位字母或数字");
+		}
+
+		StudentEntity s = studentRepo.findOne(accessUser.getUserId());
+		s.setPassword(newPassword);
+		studentRepo.save(s);
+		return s.getId();
+	}
+
 	/**
 	 * 方法注释
 	 *