refactor(core): 新增用户默认添加UserPassword

新增用户默认添加UserPassword
yun-zuoyi
wynne1005 4 years ago
parent 9f67131539
commit 8f658735b1

@ -337,13 +337,16 @@ public class WhiteController extends CoreBaseController {
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD.getDescription()).setCode(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD.getCode()); result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD.getDescription()).setCode(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD.getCode());
result.setErrorMsg(e.getMessage()); result.setErrorMsg(e.getMessage());
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR; userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR;
LOGGER.warn("Impp业务异常AuthenticationException 登录失败 ", e);
} catch (ImppBusiException e) { } catch (ImppBusiException e) {
result = ResultBean.fail(e); result = ResultBean.fail(e);
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR; userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR;
LOGGER.warn("Impp业务异常ImppBusiException 登录失败 ", e);
} catch (Exception e) { } catch (Exception e) {
result = ResultBean.fail(e.getMessage()).setCode(ImppExceptionEnum.SYSTEM_EXCEPTION.getCode()) result = ResultBean.fail(e.getMessage()).setCode(ImppExceptionEnum.SYSTEM_EXCEPTION.getCode())
.setErrorMsg(LocaleUtils.getEnumLocaleResDesc(ImppExceptionEnum.SYSTEM_EXCEPTION, ImppExceptionEnum.SYSTEM_EXCEPTION.getDescription())); .setErrorMsg(LocaleUtils.getEnumLocaleResDesc(ImppExceptionEnum.SYSTEM_EXCEPTION, ImppExceptionEnum.SYSTEM_EXCEPTION.getDescription()));
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR; userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR;
LOGGER.warn("Impp业务异常Exception 登录失败 ", e);
} finally { } finally {
// 记录登录记录 // 记录登录记录
recordSysUserLog(null, loginModel.getLoginName(), userLoginStatus.getValue()); recordSysUserLog(null, loginModel.getLoginName(), userLoginStatus.getValue());

@ -22,6 +22,7 @@ import cn.estsh.i3plus.pojo.model.platform.UserDetailModel;
import cn.estsh.i3plus.pojo.model.platform.UserDetailPagerModel; import cn.estsh.i3plus.pojo.model.platform.UserDetailPagerModel;
import cn.estsh.i3plus.pojo.model.platform.UserRolePagerModel; import cn.estsh.i3plus.pojo.model.platform.UserRolePagerModel;
import cn.estsh.i3plus.pojo.platform.bean.*; import cn.estsh.i3plus.pojo.platform.bean.*;
import cn.estsh.i3plus.pojo.platform.repository.SysUserPasswordRepository;
import cn.estsh.impp.framework.base.controller.CoreBaseController; import cn.estsh.impp.framework.base.controller.CoreBaseController;
import cn.estsh.impp.framework.boot.auth.AuthUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException; import cn.estsh.impp.framework.boot.exception.ImppBusiException;
@ -87,6 +88,9 @@ public class PersonnelController extends CoreBaseController {
@Autowired @Autowired
private SysUserPasswordUtil userPasswordUtil; private SysUserPasswordUtil userPasswordUtil;
@Autowired
private SysUserPasswordRepository userPasswordRDao;
/** /**
* *
* *
@ -150,6 +154,15 @@ public class PersonnelController extends CoreBaseController {
user.setUserInfoId(info.getId()); user.setUserInfoId(info.getId());
user.setUserPasswordLastModifyTime(TimeTool.getNowTime(true)); user.setUserPasswordLastModifyTime(TimeTool.getNowTime(true));
refreshSysUserPassword(user); refreshSysUserPassword(user);
SysUser userSaved=personnelService.saveSysUser(user);
// 添加保存passwordId进SysUser表
SysUserPassword pwd = new SysUserPassword();
pwd.setUserId(userSaved.getId());
pwd.setUserPassword(userSaved.getUserLoginPassword());
ConvertBean.serviceModelInitialize(pwd, userSaved.getUserName());
SysUserPassword savedPassword = userPasswordRDao.save(pwd);
user.setUserLoginPasswordId(savedPassword.getId());
personnelService.saveSysUser(user); personnelService.saveSysUser(user);
info.setUserId(user.getId()); info.setUserId(user.getId());

@ -729,10 +729,17 @@ public class SysUserService implements ISysUserService {
public SysUser validatePasswordByLoginNameAndReturnUser(String loginName, String password) { public SysUser validatePasswordByLoginNameAndReturnUser(String loginName, String password) {
SysUser userDb = getSysUserByLoginName(loginName); SysUser userDb = getSysUserByLoginName(loginName);
ValidatorBean.checkNotNull(userDb, "不存在的用户信息"); ValidatorBean.checkNotNull(userDb, "不存在的用户信息");
SysUserPassword userPassword = userPasswordService.get(userDb.getUserLoginPasswordId()); if (userDb.getUserLoginPasswordId() == null || userDb.getUserLoginPasswordId() <= 0) {
if (!userPassword.getUserPassword().equals(SysUserPasswordUtil.encoder(password))) { if (!userDb.getUserLoginPassword().equals(SysUserPasswordUtil.encoder(password))) {
throw new IncorrectCredentialsException("用户密码错误"); throw new IncorrectCredentialsException("用户密码错误");
}
} else {
SysUserPassword userPassword = userPasswordService.get(userDb.getUserLoginPasswordId());
if (!userPassword.getUserPassword().equals(SysUserPasswordUtil.encoder(password))) {
throw new IncorrectCredentialsException("用户密码错误");
}
} }
return userDb; return userDb;
} }

Loading…
Cancel
Save