|
|
@@ -1,4 +1,4 @@
|
|
|
-package com.wx.blink.admin.module.system.login.service;
|
|
|
+package com.wx.blink.admin.system.login.service;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpInterface;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
@@ -6,17 +6,17 @@ import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
|
-import com.wx.blink.admin.module.system.department.domain.vo.DepartmentVO;
|
|
|
-import com.wx.blink.admin.module.system.department.service.DepartmentService;
|
|
|
-import com.wx.blink.admin.module.system.employee.domain.entity.EmployeeEntity;
|
|
|
-import com.wx.blink.admin.module.system.employee.service.EmployeeService;
|
|
|
-import com.wx.blink.admin.module.system.login.domain.LoginForm;
|
|
|
-import com.wx.blink.admin.module.system.login.domain.LoginResultVO;
|
|
|
-import com.wx.blink.admin.module.system.login.domain.RequestEmployee;
|
|
|
-import com.wx.blink.admin.module.system.menu.domain.vo.MenuVO;
|
|
|
-import com.wx.blink.admin.module.system.role.domain.vo.RoleVO;
|
|
|
-import com.wx.blink.admin.module.system.role.service.RoleEmployeeService;
|
|
|
-import com.wx.blink.admin.module.system.role.service.RoleMenuService;
|
|
|
+import com.wx.blink.admin.system.department.domain.vo.DepartmentVO;
|
|
|
+import com.wx.blink.admin.system.department.service.DepartmentService;
|
|
|
+import com.wx.blink.admin.system.employee.domain.entity.EmployeeEntity;
|
|
|
+import com.wx.blink.admin.system.employee.service.EmployeeService;
|
|
|
+import com.wx.blink.admin.system.login.domain.LoginForm;
|
|
|
+import com.wx.blink.admin.system.login.domain.LoginResultVO;
|
|
|
+import com.wx.blink.admin.system.login.domain.RequestEmployee;
|
|
|
+import com.wx.blink.admin.system.menu.domain.vo.MenuVO;
|
|
|
+import com.wx.blink.admin.system.role.domain.vo.RoleVO;
|
|
|
+import com.wx.blink.admin.system.role.service.RoleEmployeeService;
|
|
|
+import com.wx.blink.admin.system.role.service.RoleMenuService;
|
|
|
import com.wx.blink.base.common.code.UserErrorCode;
|
|
|
import com.wx.blink.base.common.constant.RequestHeaderConst;
|
|
|
import com.wx.blink.base.common.constant.StringConst;
|
|
|
@@ -184,11 +184,6 @@ public class LoginService implements StpInterface {
|
|
|
String superPassword = configService.getConfigValue(ConfigKeyEnum.SUPER_PASSWORD);
|
|
|
boolean superPasswordFlag = superPassword.equals(requestPassword);
|
|
|
|
|
|
- // 校验双因子登录
|
|
|
- ResponseDTO<String> validateEmailCode = validateEmailCode(loginForm, employeeEntity, superPasswordFlag);
|
|
|
- if (!validateEmailCode.getOk()) {
|
|
|
- return ResponseDTO.error(validateEmailCode);
|
|
|
- }
|
|
|
|
|
|
// 万能密码特殊操作
|
|
|
if (superPasswordFlag) {
|
|
|
@@ -201,7 +196,7 @@ public class LoginService implements StpInterface {
|
|
|
} else {
|
|
|
|
|
|
// 按照等保登录要求,进行登录失败次数校验
|
|
|
- ResponseDTO<LoginFailEntity> loginFailEntityResponseDTO = securityLoginService.checkLogin(employeeEntity.getEmployeeId(), UserTypeEnum.ADMIN_EMPLOYEE);
|
|
|
+ ResponseDTO<LoginFailEntity> loginFailEntityResponseDTO = securityLoginService.checkLogin(employeeEntity.getEmployeeId(), UserTypeEnum.EMPLOYEE);
|
|
|
if (!loginFailEntityResponseDTO.getOk()) {
|
|
|
return ResponseDTO.error(loginFailEntityResponseDTO);
|
|
|
}
|
|
|
@@ -211,16 +206,13 @@ public class LoginService implements StpInterface {
|
|
|
// 记录登录失败
|
|
|
saveLoginLog(employeeEntity, ip, userAgent, "密码错误", LoginLogResultEnum.LOGIN_FAIL);
|
|
|
// 记录等级保护次数
|
|
|
- String msg = securityLoginService.recordLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.ADMIN_EMPLOYEE, employeeEntity.getLoginName(), loginFailEntityResponseDTO.getData());
|
|
|
+ String msg = securityLoginService.recordLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.EMPLOYEE, employeeEntity.getLoginName(), loginFailEntityResponseDTO.getData());
|
|
|
return msg == null ? ResponseDTO.userErrorParam("登录名或密码错误!") : ResponseDTO.error(UserErrorCode.LOGIN_FAIL_WILL_LOCK, msg);
|
|
|
}
|
|
|
|
|
|
- String saTokenLoginId = UserTypeEnum.ADMIN_EMPLOYEE.getValue() + StringConst.COLON + employeeEntity.getEmployeeId();
|
|
|
+ String saTokenLoginId = UserTypeEnum.EMPLOYEE.getValue() + StringConst.COLON + employeeEntity.getEmployeeId();
|
|
|
// 登录
|
|
|
StpUtil.login(saTokenLoginId, String.valueOf(loginDeviceEnum.getDesc()));
|
|
|
-
|
|
|
- // 移除邮箱验证码
|
|
|
- deleteEmailCode(employeeEntity.getEmployeeId());
|
|
|
}
|
|
|
|
|
|
// 获取员工信息
|
|
|
@@ -230,7 +222,7 @@ public class LoginService implements StpInterface {
|
|
|
loginEmployeeCache.put(employeeEntity.getEmployeeId(), requestEmployee);
|
|
|
|
|
|
// 移除登录失败
|
|
|
- securityLoginService.removeLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.ADMIN_EMPLOYEE);
|
|
|
+ securityLoginService.removeLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.EMPLOYEE);
|
|
|
|
|
|
// 获取登录结果信息
|
|
|
String token = StpUtil.getTokenValue();
|
|
|
@@ -264,7 +256,7 @@ public class LoginService implements StpInterface {
|
|
|
if (employeeEntity.getDisabledFlag()) {
|
|
|
return ResponseDTO.userErrorParam("您的账号已被禁用,请联系工作人员!");
|
|
|
}
|
|
|
- String saTokenLoginId = UserTypeEnum.ADMIN_EMPLOYEE.getValue() + StringConst.COLON + employeeEntity.getEmployeeId();
|
|
|
+ String saTokenLoginId = UserTypeEnum.EMPLOYEE.getValue() + StringConst.COLON + employeeEntity.getEmployeeId();
|
|
|
// 登录
|
|
|
StpUtil.login(saTokenLoginId, String.valueOf(loginDeviceEnum.getDesc()));
|
|
|
// 获取员工信息
|
|
|
@@ -274,7 +266,7 @@ public class LoginService implements StpInterface {
|
|
|
loginEmployeeCache.put(employeeEntity.getEmployeeId(), requestEmployee);
|
|
|
|
|
|
// 移除登录失败
|
|
|
- securityLoginService.removeLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.ADMIN_EMPLOYEE);
|
|
|
+ securityLoginService.removeLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.EMPLOYEE);
|
|
|
|
|
|
// 获取登录结果信息
|
|
|
// 获取登录结果信息
|
|
|
@@ -314,7 +306,7 @@ public class LoginService implements StpInterface {
|
|
|
if (employee.getDisabledFlag()) {
|
|
|
return ResponseDTO.userErrorParam("您的账号已被禁用,请联系工作人员");
|
|
|
}
|
|
|
- String saTokenLoginId = UserTypeEnum.ADMIN_EMPLOYEE.getValue() + StringConst.COLON + employee.getEmployeeId();
|
|
|
+ String saTokenLoginId = UserTypeEnum.EMPLOYEE.getValue() + StringConst.COLON + employee.getEmployeeId();
|
|
|
//登录
|
|
|
StpUtil.login(saTokenLoginId, String.valueOf(deviceEnum.getDesc()));
|
|
|
//获取员工信息
|
|
|
@@ -322,7 +314,7 @@ public class LoginService implements StpInterface {
|
|
|
//放入缓存
|
|
|
loginEmployeeCache.put(employee.getEmployeeId(), requestEmployee);
|
|
|
//移出登陆失败
|
|
|
- securityLoginService.removeLoginFail(employee.getEmployeeId(), UserTypeEnum.ADMIN_EMPLOYEE);
|
|
|
+ securityLoginService.removeLoginFail(employee.getEmployeeId(), UserTypeEnum.EMPLOYEE);
|
|
|
//获取 登录结果信息
|
|
|
String token = StpUtil.getTokenValue();
|
|
|
LoginResultVO loginResult = getLoginResult(requestEmployee, token);
|
|
|
@@ -355,7 +347,7 @@ public class LoginService implements StpInterface {
|
|
|
permissionCache.put(requestEmployee.getUserId(), userPermission);
|
|
|
|
|
|
// 上次登录信息
|
|
|
- LoginLogVO loginLogVO = loginLogService.queryLastByUserId(requestEmployee.getEmployeeId(), UserTypeEnum.ADMIN_EMPLOYEE, LoginLogResultEnum.LOGIN_SUCCESS);
|
|
|
+ LoginLogVO loginLogVO = loginLogService.queryLastByUserId(requestEmployee.getEmployeeId(), UserTypeEnum.EMPLOYEE, LoginLogResultEnum.LOGIN_SUCCESS);
|
|
|
if (loginLogVO != null) {
|
|
|
loginResultVO.setLastLoginIp(loginLogVO.getLoginIp());
|
|
|
loginResultVO.setLastLoginIpRegion(loginLogVO.getLoginIpRegion());
|
|
|
@@ -383,7 +375,7 @@ public class LoginService implements StpInterface {
|
|
|
|
|
|
// 基础信息
|
|
|
RequestEmployee requestEmployee = BlinkBeanUtil.copy(employeeEntity, RequestEmployee.class);
|
|
|
- requestEmployee.setUserType(UserTypeEnum.ADMIN_EMPLOYEE);
|
|
|
+ requestEmployee.setUserType(UserTypeEnum.EMPLOYEE);
|
|
|
|
|
|
// 部门信息
|
|
|
DepartmentVO department = departmentService.getDepartmentById(employeeEntity.getDepartmentId());
|
|
|
@@ -500,10 +492,10 @@ public class LoginService implements StpInterface {
|
|
|
/**
|
|
|
* 保存登录日志
|
|
|
*/
|
|
|
- private void saveLoginLog(EmployeeEntity employeeEntity, String ip, String userAgent, String remark, LoginLogResultEnum result) {
|
|
|
+ public void saveLoginLog(EmployeeEntity employeeEntity, String ip, String userAgent, String remark, LoginLogResultEnum result) {
|
|
|
LoginLogEntity loginEntity = LoginLogEntity.builder()
|
|
|
.userId(employeeEntity.getEmployeeId())
|
|
|
- .userType(UserTypeEnum.ADMIN_EMPLOYEE.getValue())
|
|
|
+ .userType(UserTypeEnum.EMPLOYEE.getValue())
|
|
|
.userName(employeeEntity.getActualName())
|
|
|
.userAgent(userAgent)
|
|
|
.loginIp(ip)
|
|
|
@@ -584,99 +576,4 @@ public class LoginService implements StpInterface {
|
|
|
|
|
|
return userPermission;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送 邮箱 验证码
|
|
|
- */
|
|
|
- public ResponseDTO<String> sendEmailCode(String loginName) {
|
|
|
-
|
|
|
- // 开启双因子登录
|
|
|
- if (!level3ProtectConfigService.isTwoFactorLoginEnabled()) {
|
|
|
- return ResponseDTO.userErrorParam("无需使用邮箱验证码");
|
|
|
- }
|
|
|
-
|
|
|
- // 验证登录名
|
|
|
- EmployeeEntity employeeEntity = employeeService.getByLoginName(loginName);
|
|
|
- if (null == employeeEntity) {
|
|
|
- return ResponseDTO.userErrorParam("登录名不存在!");
|
|
|
- }
|
|
|
- // 验证账号状态
|
|
|
- if (employeeEntity.getDeletedFlag()) {
|
|
|
- return ResponseDTO.userErrorParam("您的账号已被删除,请联系工作人员!");
|
|
|
- }
|
|
|
-
|
|
|
- // 验证账号状态
|
|
|
- if (employeeEntity.getDisabledFlag()) {
|
|
|
- return ResponseDTO.userErrorParam("您的账号已被禁用,请联系工作人员!");
|
|
|
- }
|
|
|
-
|
|
|
- String mail = employeeEntity.getEmail();
|
|
|
- if (BlinkStringUtil.isBlank(mail)) {
|
|
|
- return ResponseDTO.userErrorParam("您暂未配置邮箱地址,请联系管理员配置邮箱");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验验证码发送时间,60秒内不能重复发生
|
|
|
- String redisVerificationCodeKey = redisService.generateRedisKey(RedisKeyConst.Support.LOGIN_VERIFICATION_CODE, UserTypeEnum.ADMIN_EMPLOYEE.getValue() + RedisKeyConst.SEPARATOR + employeeEntity.getEmployeeId());
|
|
|
- String emailCode = redisService.get(redisVerificationCodeKey);
|
|
|
- long sendCodeTimeMills = -1;
|
|
|
- if (!BlinkStringUtil.isEmpty(emailCode)) {
|
|
|
- sendCodeTimeMills = NumberUtil.parseLong(emailCode.split(StringConst.UNDERLINE)[1]);
|
|
|
- }
|
|
|
-
|
|
|
- if (System.currentTimeMillis() - sendCodeTimeMills < 60 * 1000) {
|
|
|
- return ResponseDTO.userErrorParam("邮箱验证码已发送,一分钟内请勿重复发送");
|
|
|
- }
|
|
|
-
|
|
|
- //生成验证码
|
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
- String verificationCode = RandomUtil.randomNumbers(4);
|
|
|
- redisService.set(redisVerificationCodeKey, verificationCode + StringConst.UNDERLINE + currentTimeMillis, 300);
|
|
|
-
|
|
|
- // 发送邮件验证码
|
|
|
- HashMap<String, Object> mailParams = new HashMap<>();
|
|
|
- mailParams.put("code", verificationCode);
|
|
|
- return mailService.sendMail(MailTemplateCodeEnum.LOGIN_VERIFICATION_CODE, mailParams, Collections.singletonList(employeeEntity.getEmail()));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验邮箱验证码
|
|
|
- */
|
|
|
- private ResponseDTO<String> validateEmailCode(LoginForm loginForm, EmployeeEntity employeeEntity, boolean superPasswordFlag) {
|
|
|
- // 万能密码则不校验
|
|
|
- if (superPasswordFlag) {
|
|
|
- return ResponseDTO.ok();
|
|
|
- }
|
|
|
-
|
|
|
- // 未开启双因子登录
|
|
|
- if (!level3ProtectConfigService.isTwoFactorLoginEnabled()) {
|
|
|
- return ResponseDTO.ok();
|
|
|
- }
|
|
|
-
|
|
|
- if (BlinkStringUtil.isEmpty(loginForm.getEmailCode())) {
|
|
|
- return ResponseDTO.userErrorParam("请输入邮箱验证码");
|
|
|
- }
|
|
|
-
|
|
|
- // 校验验证码
|
|
|
- String redisVerificationCodeKey = redisService.generateRedisKey(RedisKeyConst.Support.LOGIN_VERIFICATION_CODE, UserTypeEnum.ADMIN_EMPLOYEE.getValue() + RedisKeyConst.SEPARATOR + employeeEntity.getEmployeeId());
|
|
|
- String emailCode = redisService.get(redisVerificationCodeKey);
|
|
|
- if (BlinkStringUtil.isEmpty(emailCode)) {
|
|
|
- return ResponseDTO.userErrorParam("邮箱验证码已失效,请重新发送");
|
|
|
- }
|
|
|
-
|
|
|
- if (!emailCode.split(StringConst.UNDERLINE)[0].equals(loginForm.getEmailCode().trim())) {
|
|
|
- return ResponseDTO.userErrorParam("邮箱验证码错误,请重新填写");
|
|
|
- }
|
|
|
-
|
|
|
- return ResponseDTO.ok();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 移除邮箱验证码
|
|
|
- */
|
|
|
- private void deleteEmailCode(Long employeeId) {
|
|
|
- String redisVerificationCodeKey = redisService.generateRedisKey(RedisKeyConst.Support.LOGIN_VERIFICATION_CODE, UserTypeEnum.ADMIN_EMPLOYEE.getValue() + RedisKeyConst.SEPARATOR + employeeId);
|
|
|
- redisService.delete(redisVerificationCodeKey);
|
|
|
- }
|
|
|
}
|