|
@@ -2,6 +2,10 @@ package com.ruoyi.web.service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
+import com.ruoyi.common.enums.ErrorCodes;
|
|
|
|
|
+import com.ruoyi.common.exception.ErrorException;
|
|
|
import com.ruoyi.common.utils.PhoneUtils;
|
|
import com.ruoyi.common.utils.PhoneUtils;
|
|
|
import com.ruoyi.framework.web.service.TokenService;
|
|
import com.ruoyi.framework.web.service.TokenService;
|
|
|
import com.ruoyi.system.service.ShortMessageService;
|
|
import com.ruoyi.system.service.ShortMessageService;
|
|
@@ -34,6 +38,8 @@ import com.ruoyi.system.service.ISysConfigService;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 登录校验方法
|
|
* 登录校验方法
|
|
|
*
|
|
*
|
|
@@ -69,7 +75,7 @@ public class SysLoginService
|
|
|
* @param uuid
|
|
* @param uuid
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String login(String mobile, String username, String password, String code, String uuid) {
|
|
|
|
|
|
|
+ public AjaxResult login(String mobile, String username, String password, String code, String uuid) {
|
|
|
if (StringUtils.isNotBlank(mobile)) {
|
|
if (StringUtils.isNotBlank(mobile)) {
|
|
|
if (!shortMessageService.checkCode(mobile, password)) {
|
|
if (!shortMessageService.checkCode(mobile, password)) {
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(mobile, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(mobile, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
|
|
@@ -103,6 +109,14 @@ public class SysLoginService
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
|
|
|
|
|
+ if(e.getCause() instanceof ErrorException) {
|
|
|
|
|
+ ErrorException errorException = (ErrorException) e.getCause();
|
|
|
|
|
+ Map map = Maps.newHashMap();
|
|
|
|
|
+ ErrorCodes errorCode = errorException.getErrorCode();
|
|
|
|
|
+ map.put("code", errorCode.getCode());
|
|
|
|
|
+ map.put("message", StringUtils.isNotEmpty(errorException.getMessage()) ? errorException.getMessage() : errorCode.getTitle());
|
|
|
|
|
+ return AjaxResult.success(map);
|
|
|
|
|
+ }
|
|
|
throw new ServiceException(e.getMessage());
|
|
throw new ServiceException(e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -114,7 +128,9 @@ public class SysLoginService
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
recordLoginInfo(loginUser.getUserId());
|
|
recordLoginInfo(loginUser.getUserId());
|
|
|
// 生成token
|
|
// 生成token
|
|
|
- return tokenService.createToken(loginUser);
|
|
|
|
|
|
|
+ AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
+ ajax.put(Constants.TOKEN, tokenService.createToken(loginUser));
|
|
|
|
|
+ return ajax;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|