|
@@ -19,12 +19,11 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
/**
|
|
|
* 登录校验方法
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
@Component
|
|
|
-public class SysLoginService
|
|
|
-{
|
|
|
+public class SysLoginService {
|
|
|
|
|
|
@Autowired
|
|
|
private ISysLogininforService sysLogininforService;
|
|
@@ -35,50 +34,43 @@ public class SysLoginService
|
|
|
/**
|
|
|
* 登录
|
|
|
*/
|
|
|
- public LoginUser login(String username, String password,Integer tenantId)
|
|
|
- {
|
|
|
+ public LoginUser login(String username, String password, Integer tenantId) {
|
|
|
// 用户名或密码为空 错误
|
|
|
- if (StringUtils.isAnyBlank(username, password))
|
|
|
- {
|
|
|
+ if (StringUtils.isAnyBlank(username, password)) {
|
|
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
|
|
throw new BusinessException("用户/密码必须填写");
|
|
|
}
|
|
|
// 密码如果不在指定范围内 错误
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
- || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
|
|
- {
|
|
|
+ || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
|
|
throw new BusinessException("用户密码不在指定范围");
|
|
|
}
|
|
|
// 用户名不在指定范围内 错误
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
- || username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
|
|
- {
|
|
|
+ || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
|
|
throw new BusinessException("用户名不在指定范围");
|
|
|
}
|
|
|
|
|
|
// 查询用户信息
|
|
|
LoginUser loginUser = new LoginUser();
|
|
|
- if (tenantId!=null&&tenantId!=0){
|
|
|
- loginUser = sysUserService.getUserInfoOne(username,tenantId);
|
|
|
- }else {
|
|
|
+ if (tenantId != null && tenantId != 0) {
|
|
|
+ loginUser = sysUserService.getUserInfoOne(username, tenantId);
|
|
|
+ } else {
|
|
|
loginUser = sysUserService.getUserInfo(username);
|
|
|
}
|
|
|
|
|
|
SysUserVO user = loginUser.getSysUser();
|
|
|
- if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
|
|
- {
|
|
|
+ if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
|
|
recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
|
throw new BusinessException("对不起,您的账号:" + username + " 已被删除");
|
|
|
}
|
|
|
- if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
|
|
- {
|
|
|
+ if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
throw new BusinessException("对不起,您的账号:" + username + " 已停用");
|
|
|
}
|
|
|
- if (!SecurityUtils.matchesPassword(password, user.getPassword()))
|
|
|
- {
|
|
|
+ if (!SecurityUtils.matchesPassword(password, user.getPassword())) {
|
|
|
recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
|
|
|
throw new BusinessException("用户不存在/密码错误");
|
|
|
}
|
|
@@ -86,29 +78,73 @@ public class SysLoginService
|
|
|
return loginUser;
|
|
|
}
|
|
|
|
|
|
- public void logout(String loginName)
|
|
|
- {
|
|
|
+
|
|
|
+ public SysUser appLogin(String username, String password, Integer tenantId, String phone) {
|
|
|
+ SysUser loginUser = new SysUser();
|
|
|
+ if (username != null && !"".equals(username)) {
|
|
|
+ // 用户名或密码为空 错误
|
|
|
+ if (StringUtils.isAnyBlank(username, password)) {
|
|
|
+ recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
|
|
+ throw new BusinessException("用户/密码必须填写");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码如果不在指定范围内 错误
|
|
|
+ if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
+ || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
+ recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
|
|
+ throw new BusinessException("用户密码不在指定范围");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户名不在指定范围内 错误
|
|
|
+ if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
+ || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
+ recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
|
|
+ throw new BusinessException("用户名不在指定范围");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询用户信息
|
|
|
+ loginUser = sysUserService.getAppUserInfo(username, tenantId);
|
|
|
+
|
|
|
+ if (!SecurityUtils.matchesPassword(password, loginUser.getPassword())) {
|
|
|
+ recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
|
|
|
+ throw new BusinessException("用户不存在/密码错误");
|
|
|
+ }
|
|
|
+ } else if (phone != null && !"".equals(phone)) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (UserStatus.DELETED.getCode().equals(loginUser.getDelFlag())) {
|
|
|
+ recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
|
+ throw new BusinessException("对不起,您的账号:" + username + " 已被删除");
|
|
|
+ }
|
|
|
+ if (UserStatus.DISABLE.getCode().equals(loginUser.getStatus())) {
|
|
|
+ recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
+ throw new BusinessException("对不起,您的账号:" + username + " 已停用");
|
|
|
+ }
|
|
|
+
|
|
|
+ recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
|
|
+ return loginUser;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void logout(String loginName) {
|
|
|
recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 注册
|
|
|
*/
|
|
|
- public void register(String username, String password)
|
|
|
- {
|
|
|
+ public void register(String username, String password) {
|
|
|
// 用户名或密码为空 错误
|
|
|
- if (StringUtils.isAnyBlank(username, password))
|
|
|
- {
|
|
|
+ if (StringUtils.isAnyBlank(username, password)) {
|
|
|
throw new BusinessException("用户/密码必须填写");
|
|
|
}
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
- || username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
|
|
- {
|
|
|
+ || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
throw new BusinessException("账户长度必须在2到20个字符之间");
|
|
|
}
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
- || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
|
|
- {
|
|
|
+ || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
throw new BusinessException("密码长度必须在5到20个字符之间");
|
|
|
}
|
|
|
|
|
@@ -123,25 +159,21 @@ public class SysLoginService
|
|
|
|
|
|
/**
|
|
|
* 记录登录信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param username 用户名
|
|
|
- * @param status 状态
|
|
|
- * @param message 消息内容
|
|
|
+ * @param status 状态
|
|
|
+ * @param message 消息内容
|
|
|
* @return
|
|
|
*/
|
|
|
- public void recordLogininfor(String username, String status, String message)
|
|
|
- {
|
|
|
+ public void recordLogininfor(String username, String status, String message) {
|
|
|
SysLogininforVO logininfor = new SysLogininforVO();
|
|
|
logininfor.setUserName(username);
|
|
|
logininfor.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
|
logininfor.setMsg(message);
|
|
|
// 日志状态
|
|
|
- if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER))
|
|
|
- {
|
|
|
+ if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER)) {
|
|
|
logininfor.setStatus(Constants.LOGIN_SUCCESS_STATUS);
|
|
|
- }
|
|
|
- else if (Constants.LOGIN_FAIL.equals(status))
|
|
|
- {
|
|
|
+ } else if (Constants.LOGIN_FAIL.equals(status)) {
|
|
|
logininfor.setStatus(Constants.LOGIN_FAIL_STATUS);
|
|
|
}
|
|
|
sysLogininforService.insertLogininfor(BeanMapperUtils.map(logininfor, SysLogininfor.class));
|