|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.exam.reserve.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.boot.core.security.annotation.AuthorizationComponent;
|
|
|
import com.qmth.boot.core.security.service.AuthorizationService;
|
|
@@ -27,6 +28,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@Service
|
|
|
@AuthorizationComponent
|
|
@@ -90,6 +92,7 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
|
|
|
|
|
|
loginUser.setSessionId(LoginSessionManager.USER_LOGIN + user.getId());
|
|
|
loginUser.setToken(FastUUID.get());
|
|
|
+ loginUser.setFirstLogin(user.getFirstLogin() == null ? Boolean.TRUE : user.getFirstLogin());
|
|
|
loginSessionManager.addLoginSession(loginUser);
|
|
|
|
|
|
log.info("[USER_LOGIN] success! account:{} {} {}", loginUser.getAccount(), loginUser.getName(), loginUser.getRole());
|
|
@@ -188,6 +191,30 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
|
|
|
log.warn("[LOGOUT] account:{} {}", loginUser.getAccount(), loginUser.getName());
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void modifyPassword(Long id, String password) {
|
|
|
+ if (StringUtils.isBlank(password)) {
|
|
|
+ throw new StatusException("密码不能为空");
|
|
|
+ }
|
|
|
+ String regex = "^[a-zA-Z0-9]{6,12}$";
|
|
|
+ if (!password.matches(regex)) {
|
|
|
+ throw new StatusException("密码必须为:6-12位的大小写字母或者数字");
|
|
|
+ }
|
|
|
+ String encodePassword = DigestUtils.sha256Hex(password).toUpperCase();
|
|
|
+ UserEntity user = userService.getById(id);
|
|
|
+ if (user.getPassword().equals(encodePassword)) {
|
|
|
+ throw new StatusException("修改的密码不能和原密码相同");
|
|
|
+ }
|
|
|
+ userService.update(new UpdateWrapper<UserEntity>().lambda().set(UserEntity::getPassword, encodePassword).eq(UserEntity::getId, id));
|
|
|
+ //更新修改密码标志
|
|
|
+ if (user.getFirstLogin() == null || user.getFirstLogin()) {
|
|
|
+ userService.update(
|
|
|
+ new UpdateWrapper<UserEntity>().lambda().set(UserEntity::getFirstLogin, Boolean.FALSE).eq(UserEntity::getId, id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public LoginUser findByIdentity(String identity, SignatureType type, String path) {
|
|
|
return loginSessionManager.getLoginSession(identity);
|