|
@@ -19,6 +19,8 @@ import com.ruoyi.system.api.RemoteUserService;
|
|
|
import com.ruoyi.system.api.domain.SysUser;
|
|
import com.ruoyi.system.api.domain.SysUser;
|
|
|
import com.ruoyi.system.api.model.LoginUser;
|
|
import com.ruoyi.system.api.model.LoginUser;
|
|
|
|
|
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 登录校验方法
|
|
* 登录校验方法
|
|
|
*
|
|
*
|
|
@@ -42,7 +44,7 @@ public class SysLoginService
|
|
|
/**
|
|
/**
|
|
|
* 登录
|
|
* 登录
|
|
|
*/
|
|
*/
|
|
|
- public LoginUser login(String username, String password)
|
|
|
|
|
|
|
+ public LoginUser login(String username, String password,String phoneNumber)
|
|
|
{
|
|
{
|
|
|
// 用户名或密码为空 错误
|
|
// 用户名或密码为空 错误
|
|
|
if (StringUtils.isAnyBlank(username, password))
|
|
if (StringUtils.isAnyBlank(username, password))
|
|
@@ -71,8 +73,13 @@ public class SysLoginService
|
|
|
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
|
|
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
|
|
|
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
|
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
|
|
}
|
|
}
|
|
|
- // 查询用户信息
|
|
|
|
|
- R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
|
|
|
|
|
|
+ R<LoginUser> userResult;
|
|
|
|
|
+ if (phoneNumber != null){// H5 登录根据手机号查询出用户信息进行后续流程
|
|
|
|
|
+ userResult = remoteUserService.getUserByPhoneNumber(phoneNumber, SecurityConstants.INNER);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ // 查询用户信息
|
|
|
|
|
+ userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (R.FAIL == userResult.getCode())
|
|
if (R.FAIL == userResult.getCode())
|
|
|
{
|
|
{
|
|
@@ -91,12 +98,23 @@ public class SysLoginService
|
|
|
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
|
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
|
|
}
|
|
}
|
|
|
|
|
+ // 验证手机号格式
|
|
|
|
|
+ if (isMobile(username)) {
|
|
|
|
|
+ if (!user.getPhonenumber().equals(username)) {
|
|
|
|
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "手机号不匹配");
|
|
|
|
|
+ throw new ServiceException("手机号不匹配");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
passwordService.validate(user, password);
|
|
passwordService.validate(user, password);
|
|
|
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
|
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
|
|
recordLoginInfo(user.getUserId());
|
|
recordLoginInfo(user.getUserId());
|
|
|
return userInfo;
|
|
return userInfo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private boolean isMobile(String str) {
|
|
|
|
|
+ // 使用正则表达式验证手机号
|
|
|
|
|
+ return Pattern.matches("^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0-8]|18[0-9]|19[89])\\d{8}$", str);
|
|
|
|
|
+}
|
|
|
/**
|
|
/**
|
|
|
* 记录登录信息
|
|
* 记录登录信息
|
|
|
*
|
|
*
|
|
@@ -121,7 +139,7 @@ public class SysLoginService
|
|
|
/**
|
|
/**
|
|
|
* 注册
|
|
* 注册
|
|
|
*/
|
|
*/
|
|
|
- public void register(String username, String password)
|
|
|
|
|
|
|
+ public void register(String username, String password,String phoneNumber)
|
|
|
{
|
|
{
|
|
|
// 用户名或密码为空 错误
|
|
// 用户名或密码为空 错误
|
|
|
if (StringUtils.isAnyBlank(username, password))
|
|
if (StringUtils.isAnyBlank(username, password))
|
|
@@ -138,11 +156,16 @@ public class SysLoginService
|
|
|
{
|
|
{
|
|
|
throw new ServiceException("密码长度必须在5到20个字符之间");
|
|
throw new ServiceException("密码长度必须在5到20个字符之间");
|
|
|
}
|
|
}
|
|
|
|
|
+ // 验证手机号格式
|
|
|
|
|
+ if (!isMobile(phoneNumber)) {
|
|
|
|
|
+ throw new ServiceException("手机号不匹配");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 注册用户信息
|
|
// 注册用户信息
|
|
|
SysUser sysUser = new SysUser();
|
|
SysUser sysUser = new SysUser();
|
|
|
sysUser.setUserName(username);
|
|
sysUser.setUserName(username);
|
|
|
sysUser.setNickName(username);
|
|
sysUser.setNickName(username);
|
|
|
|
|
+ sysUser.setPhonenumber(phoneNumber);
|
|
|
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
|
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
|
|
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
|
|
|
|
|
|