多语言-BusiStatus整合
This commit is contained in:
@@ -1,197 +0,0 @@
|
||||
package com.accompany.oauth2.constant;
|
||||
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.status.BusiStatusInterface;
|
||||
|
||||
/**
|
||||
* @author liuguofu
|
||||
*/
|
||||
public enum OAuthStatus implements BusiStatusInterface {
|
||||
|
||||
ACCESS_DENIED(100,"access denied"), //拒絕訪問
|
||||
|
||||
INVALID_REQUEST(101,"invalid request"), //請求不合法
|
||||
|
||||
INVALID_REQUEST_SCHEME(102,"invalid request scheme"), //錯誤的請求協議
|
||||
|
||||
INVALID_REQUEST_METHOD(103,"invalid request method"), //錯誤的請求方法
|
||||
|
||||
INVALID_CLIENT_ID(104,"invalid client id"), //client id不存在或已刪除
|
||||
|
||||
CLIENT_ID_IS_BLOCKED(105,"client id is blocked"), //client id已被禁用
|
||||
|
||||
UNAUTHORIZED_CLIENT_ID(106,"unauthorized client id"), //client id未授權
|
||||
|
||||
USERNAME_PASSWORD_MISMATCH(107,"用戶名密碼不匹配"), //用戶名密碼不匹配
|
||||
|
||||
INVALID_REQUEST_SCOPE(108,"invalid request scope"), //訪問的scope不合法,開發者不用太關注,一般不會出現該錯誤
|
||||
|
||||
INVALID_USER(109,"用戶不存在或密碼錯誤"), //用戶不存在或已刪除
|
||||
|
||||
USER_HAS_BLOCKED(110,"user has blocked"), //用戶已被屏蔽
|
||||
|
||||
INVALID_TOKEN(111,"invalid token"), //token不存在或已被用戶刪除,或者用戶修改了密碼
|
||||
|
||||
ACCESS_TOKEN_IS_MISSING(112,"access token is missing"), //未找到access_token
|
||||
|
||||
ACCESS_TOKEN_HAS_EXPIRED(113,"access token has expired"), //access_token已過期
|
||||
|
||||
INVALID_REQUEST_URI(114,"invalid request uri"), //請求地址未註冊
|
||||
|
||||
INVALID_CREDENTIAL_1(115,"invalid credential 1"), //用戶未授權訪問此數據
|
||||
|
||||
INVALID_CREDENTIAL_2(116,"invalid credential 2"), //client id未申請此權限
|
||||
|
||||
NOT_TRIAL_USER(117,"not trial user"), //未註冊的測試用戶
|
||||
|
||||
REQUIRED_PARAMETER_IS_MISSING(118,"required parameter is missing"), //缺少參數
|
||||
|
||||
INVALID_GRANT(119,"invalid grant type"),
|
||||
|
||||
UNSUPPORTED_GRANT_TYPE(120,"unsupported grant type"), //錯誤的grant_type
|
||||
|
||||
UNSUPPORTED_RESPONSE_TYPE(121,"unsupported response type"), //錯誤的response_type
|
||||
|
||||
CLIENT_SECRET_MISMATCH(122,"client secret mismatch"), //client_secret不匹配
|
||||
|
||||
REDIRECT_URI_MISMATCH(123,"redirect uri mismatch"), //redirect_uri不匹配
|
||||
|
||||
INVALID_AUTHORIZATION_CODE(124,"invalid authorization code"), //authorization_code不存在或已過期
|
||||
|
||||
ACCESS_TOKEN_HAS_EXPIRED_SINCE_PASSWORD_CHANGED(125,"access token has expired since password changed"), //因用戶修改密碼而導致access_token過期
|
||||
|
||||
ACCESS_TOKEN_HAS_NOT_EXPIRED(126,"access token has not expired"), //access_token未過期;
|
||||
|
||||
UNSUPPORTED_TICKET_ISSUE_TYPE(127,"unsupported ticket issue type"),
|
||||
|
||||
INVALID_TICKET(128,"invalid ticket"),//ticket不存在或已過期
|
||||
|
||||
TICKET_IS_MISSING(129,"ticket is missing"), //未找到ticket
|
||||
|
||||
TICKET_HAS_EXPIRED(130,"ticket has expired"), //ticket過期
|
||||
|
||||
TICKET_HAS_NOT_EXPIRED(131,"ticket has not expired"), //ticket未過期
|
||||
|
||||
TICKET_HAS_EXPIRED_SINCE_PASSWORD_CHANGED(132,"ticket has expired since password changed"), //因為用戶修改密碼而ticket過期
|
||||
|
||||
INVALID_SCOPE(133,"invalid scope"),
|
||||
|
||||
RATE_LIMIT_EXCEEDED1(134,"rate limit exceeded 1"), //用戶訪問速度限制
|
||||
|
||||
RATE_LIMIT_EXCEEDED2(135,"rate limit exceeded 2"), //IP訪問速度限制
|
||||
|
||||
INVALID_IDENTIFYING_CODE(150, "短信驗證碼不正確"), //不可用的驗證碼
|
||||
|
||||
INVALID_USERNAME(151,"invalid username"), //用戶名不合法
|
||||
|
||||
USER_HAS_SIGNED_UP(152,"user has signed up"), //用戶名已被註冊
|
||||
|
||||
INVALID_RESET_CODE(153,"invalid reset code"), //重置碼無效
|
||||
|
||||
INVALID_NICK(161,"invalid nick"), //昵稱不合法
|
||||
|
||||
INVALID_THIRD_TOKEN(162,"invalid third token"), //第三方token不合法
|
||||
|
||||
THIRD_ACCOUNT_HAVE_BIND(163,"the third account have bind"), //第三方賬戶已經綁定或之前已使用該賬戶登陸過系統
|
||||
|
||||
UNBIND_OPENID_NOT_MATCH(164,"unbind openId not match error" ), //賬戶解綁失敗
|
||||
|
||||
UNBIND_MAIN_ACCOUNT(165,"unbind main account error"), //解綁主賬戶錯誤
|
||||
|
||||
PARAMETERILLEGAL(166, "parameter illegal"),
|
||||
|
||||
USER_NOT_EXISTED(167, "用戶不存在"),
|
||||
|
||||
SUCCESS(200,"success"), //成功
|
||||
|
||||
INVALID_SERVICE(199,"invalid service"),//服務不可用
|
||||
SIGN_IP_TO_OFTEN(301,"註冊過於頻繁"),//註冊過於頻繁
|
||||
SMS_IP_TO_OFTEN(302,"獲取短信過於頻繁"),//獲取短信過於頻繁
|
||||
|
||||
ACCOUNT_ERROR(407,"用戶賬號異常,請聯繫官方客服"),//賬號異常-賬號被封
|
||||
DECEIVE_ERROR(408,"用戶賬號異常,請聯繫官方客服"),//賬號異常-設備被封
|
||||
|
||||
VERSION_ERROR(409,"版本過低,請升級版本"),
|
||||
|
||||
UNKNOWN(999,"unknown"), //未知錯誤
|
||||
|
||||
ALREADY_BOUND(1799,"該賬號已經綁定過"), //缺少參數
|
||||
|
||||
ALREADY_BOUND_WEIXIN(1811,"該賬號已經綁定微信"),
|
||||
|
||||
WEAK_PASSWORD(3001, "密碼必須使用6-16個字符內的數字和英文字母組合哦"),
|
||||
|
||||
VERIFY_CODE_ERROR(3002, "驗證碼結果不正確"),
|
||||
|
||||
CLOSE_SIGNUP_ERROR(3003, "需要更新版本才可以註冊哦"),
|
||||
|
||||
APP_VERSION_TOO_OLD(3004, BusiStatus.VERSIONTOOOLD.getReasonPhrase()),
|
||||
|
||||
SUPER_ADMIN_USER_ERROR(136, "超級管理員error:136"),
|
||||
|
||||
INVALID_LOGIN_TYPE_ERROR(3004, "該賬號只允許通過ID登錄"),
|
||||
|
||||
PHONE_BIND_TOO_MANY_ACCOUNT(3005, "該手機號存在多個ID的綁定關係,請聯繫公會運營處理"),
|
||||
|
||||
PHONE_BIND_TOO_MANY_ACCOUNT2(25002, "該手機號存在多個ID的綁定關係,請輸入用戶ID進行登錄"),
|
||||
|
||||
PHONE_BE_INTERCEPTED(3006, BusiStatus.PHONE_BE_INTERCEPTED.getReasonPhrase()),
|
||||
PASSWORD_ERROR(3007, "手機號或密碼錯誤"),
|
||||
OLD_PASSWORD_ERROR(3008, "原密碼錯誤"),
|
||||
|
||||
ACCOUNT_CANCEL(3009, "該賬號已註銷"),
|
||||
ACCOUNT_CANCEL_INFO_NOT_EXIST(3010, "獲取不到賬號註銷信息"),
|
||||
PWD_WRONG_OVER_LIMIT(3011, "密碼錯誤次數過多,請10分鐘后重試"),
|
||||
|
||||
PHONE_BIND_ERROR(3012, "绑定手机号错误,请重新输入"),
|
||||
ACCOUNT_NOT_BIND_PHONE(3013, "未绑定手机号"),
|
||||
|
||||
;
|
||||
|
||||
|
||||
private final int value;
|
||||
|
||||
private final String reasonPhrase;
|
||||
|
||||
private OAuthStatus(int value, String reasonPhrase) {
|
||||
this.value = value;
|
||||
this.reasonPhrase = reasonPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the integer value of this status code.
|
||||
*/
|
||||
public int value() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the reason phrase of this status code.
|
||||
*/
|
||||
public String getReasonPhrase() {
|
||||
return reasonPhrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this status code.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return getReasonPhrase();
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package com.accompany.oauth2.result;
|
||||
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
|
||||
public class ServiceRes<T> {
|
||||
private int code;
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
public ServiceRes(OAuthStatus status) {
|
||||
this(status, null);
|
||||
}
|
||||
|
||||
public ServiceRes(OAuthStatus status, T data) {
|
||||
this.code = status.value();
|
||||
this.message = status.getReasonPhrase();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
package com.accompany.oauth2.exception;
|
||||
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
@@ -19,7 +19,7 @@ public class CustomOAuthExceptionJacksonSerializer extends StdSerializer<CustomO
|
||||
jgen.writeStartObject();
|
||||
String errorCode = value.getOAuth2ErrorCode();
|
||||
|
||||
OAuthStatus status;
|
||||
BusiStatus status;
|
||||
String errorMessage;
|
||||
String reasonPhrase = null;
|
||||
|
||||
@@ -27,130 +27,130 @@ public class CustomOAuthExceptionJacksonSerializer extends StdSerializer<CustomO
|
||||
case CustomOAuth2Exception.INVALID_CLIENT:
|
||||
errorMessage = value.getMessage().toLowerCase();
|
||||
if(errorMessage.contains("bad") && errorMessage.contains("credentials")){
|
||||
status = OAuthStatus.CLIENT_SECRET_MISMATCH;
|
||||
status = BusiStatus.CLIENT_SECRET_MISMATCH;
|
||||
}else {
|
||||
status = OAuthStatus.INVALID_CLIENT_ID;
|
||||
status = BusiStatus.INVALID_CLIENT_ID;
|
||||
}
|
||||
break;
|
||||
case CustomOAuth2Exception.UNAUTHORIZED:
|
||||
errorMessage = value.getMessage().toLowerCase();
|
||||
if(errorMessage.contains("user") && errorMessage.contains("not found")) {
|
||||
status = OAuthStatus.INVALID_USER;
|
||||
status = BusiStatus.INVALID_USER;
|
||||
} else {
|
||||
status = OAuthStatus.INVALID_REQUEST;
|
||||
status = BusiStatus.INVALID_REQUEST;
|
||||
}
|
||||
break;
|
||||
case CustomOAuth2Exception.UNAUTHORIZED_CLIENT:
|
||||
status = OAuthStatus.UNAUTHORIZED_CLIENT_ID;
|
||||
status = BusiStatus.UNAUTHORIZED_CLIENT_ID;
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_GRANT:
|
||||
errorMessage = value.getMessage().toLowerCase();
|
||||
if (errorMessage.contains("redirect") && errorMessage.contains("match")) {
|
||||
status = OAuthStatus.REDIRECT_URI_MISMATCH;
|
||||
status = BusiStatus.REDIRECT_URI_MISMATCH;
|
||||
}else if(errorMessage.contains("bad") && errorMessage.contains("credentials")){
|
||||
status = OAuthStatus.USERNAME_PASSWORD_MISMATCH;
|
||||
status = BusiStatus.USERNAME_PASSWORD_MISMATCH;
|
||||
}else if(errorMessage.contains("invalid refresh token")){
|
||||
status = OAuthStatus.INVALID_TOKEN;
|
||||
status = BusiStatus.INVALID_TOKEN;
|
||||
}else {
|
||||
status = OAuthStatus.INVALID_GRANT;
|
||||
status = BusiStatus.INVALID_GRANT;
|
||||
}
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_SCOPE:
|
||||
status = OAuthStatus.INVALID_SCOPE;
|
||||
status = BusiStatus.INVALID_SCOPE;
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_TOKEN:
|
||||
errorMessage = value.getMessage().toLowerCase();
|
||||
if(errorMessage.contains("access token expired")){
|
||||
status = OAuthStatus.ACCESS_TOKEN_HAS_EXPIRED;
|
||||
status = BusiStatus.ACCESS_TOKEN_HAS_EXPIRED;
|
||||
}else{
|
||||
status = OAuthStatus.INVALID_TOKEN;
|
||||
status = BusiStatus.INVALID_TOKEN;
|
||||
}
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_REQUEST:
|
||||
status = OAuthStatus.INVALID_REQUEST;
|
||||
status = BusiStatus.INVALID_REQUEST;
|
||||
break;
|
||||
case CustomOAuth2Exception.REDIRECT_URI_MISMATCH:
|
||||
status = OAuthStatus.REDIRECT_URI_MISMATCH;
|
||||
status = BusiStatus.REDIRECT_URI_MISMATCH;
|
||||
break;
|
||||
case CustomOAuth2Exception.UNSUPPORTED_GRANT_TYPE:
|
||||
status = OAuthStatus.UNSUPPORTED_GRANT_TYPE;
|
||||
status = BusiStatus.UNSUPPORTED_GRANT_TYPE;
|
||||
break;
|
||||
case CustomOAuth2Exception.UNSUPPORTED_RESPONSE_TYPE:
|
||||
status = OAuthStatus.UNSUPPORTED_RESPONSE_TYPE;
|
||||
status = BusiStatus.UNSUPPORTED_RESPONSE_TYPE;
|
||||
break;
|
||||
case CustomOAuth2Exception.ACCESS_DENIED:
|
||||
status = OAuthStatus.ACCESS_DENIED;
|
||||
status = BusiStatus.ACCESS_DENIED;
|
||||
break;
|
||||
case CustomOAuth2Exception.UNSUPPORTED_ISSUE_TYPE:
|
||||
status = OAuthStatus.UNSUPPORTED_TICKET_ISSUE_TYPE;
|
||||
status = BusiStatus.UNSUPPORTED_TICKET_ISSUE_TYPE;
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_USER:
|
||||
status = OAuthStatus.INVALID_USER;
|
||||
status = BusiStatus.INVALID_USER;
|
||||
break;
|
||||
case CustomOAuth2Exception.THIRD_ACCOUNT_HAS_BIND:
|
||||
status = OAuthStatus.THIRD_ACCOUNT_HAVE_BIND;
|
||||
status = BusiStatus.THIRD_ACCOUNT_HAVE_BIND;
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_THIRD_PARTY_TOKEN:
|
||||
status = OAuthStatus.INVALID_THIRD_TOKEN;
|
||||
status = BusiStatus.INVALID_THIRD_TOKEN;
|
||||
break;
|
||||
case CustomOAuth2Exception.SIGN_IP_TO_OFTEN:
|
||||
status = OAuthStatus.SIGN_IP_TO_OFTEN;
|
||||
status = BusiStatus.SIGN_IP_TO_OFTEN;
|
||||
break;
|
||||
case CustomOAuth2Exception.SMS_IP_TO_OFTEN:
|
||||
status = OAuthStatus.SMS_IP_TO_OFTEN;
|
||||
status = BusiStatus.SMS_IP_TO_OFTEN;
|
||||
break;
|
||||
case CustomOAuth2Exception.VERIFY_CODE_ERROR:
|
||||
status = OAuthStatus.VERIFY_CODE_ERROR;
|
||||
status = BusiStatus.VERIFY_CODE_ERROR;
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_BIND:
|
||||
status = OAuthStatus.ALREADY_BOUND;
|
||||
status = BusiStatus.ALREADY_BOUND;
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_BIND_WEIXIN:
|
||||
status = OAuthStatus.ALREADY_BOUND_WEIXIN;
|
||||
status = BusiStatus.ALREADY_BOUND_WEIXIN;
|
||||
break;
|
||||
case CustomOAuth2Exception.ACCOUNT_ERROR:
|
||||
status = OAuthStatus.ACCOUNT_ERROR;
|
||||
status = BusiStatus.ACCOUNT_ERROR;
|
||||
break;
|
||||
case CustomOAuth2Exception.DECEIVE_ERROR:
|
||||
status = OAuthStatus.DECEIVE_ERROR;
|
||||
status = BusiStatus.DECEIVE_ERROR;
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_SUPER_USER:
|
||||
status = OAuthStatus.SUPER_ADMIN_USER_ERROR;
|
||||
status = BusiStatus.SUPER_ADMIN_USER_ERROR;
|
||||
break;
|
||||
case CustomOAuth2Exception.INVALID_LOGIN_TYPE:
|
||||
status = OAuthStatus.INVALID_LOGIN_TYPE_ERROR;
|
||||
status = BusiStatus.INVALID_LOGIN_TYPE_ERROR;
|
||||
break;
|
||||
case CustomOAuth2Exception.USER_NOT_EXISTED:
|
||||
status = OAuthStatus.USER_NOT_EXISTED;
|
||||
status = BusiStatus.USER_NOT_EXISTED;
|
||||
break;
|
||||
case CustomOAuth2Exception.PHONE_BIND_TOO_MANY_ACCOUNT:
|
||||
if (value.getMessage().contains("请输入用户ID进行登录")) {
|
||||
status = OAuthStatus.PHONE_BIND_TOO_MANY_ACCOUNT2;
|
||||
status = BusiStatus.PHONE_BIND_TOO_MANY_ACCOUNT2;
|
||||
} else {
|
||||
status = OAuthStatus.PHONE_BIND_TOO_MANY_ACCOUNT;
|
||||
status = BusiStatus.PHONE_BIND_TOO_MANY_ACCOUNT;
|
||||
}
|
||||
break;
|
||||
case CustomOAuth2Exception.APP_VERSION_TOO_OLD:
|
||||
status = OAuthStatus.APP_VERSION_TOO_OLD;
|
||||
status = BusiStatus.APP_VERSION_TOO_OLD;
|
||||
break;
|
||||
case CustomOAuth2Exception.PHONE_BE_INTERCEPTED:
|
||||
status = OAuthStatus.PHONE_BE_INTERCEPTED;
|
||||
status = BusiStatus.PHONE_BE_INTERCEPTED;
|
||||
break;
|
||||
case CustomOAuth2Exception.PASSWORD_ERROR:
|
||||
status = OAuthStatus.PASSWORD_ERROR;
|
||||
status = BusiStatus.PASSWORD_ERROR;
|
||||
reasonPhrase = value.getMessage();
|
||||
break;
|
||||
case CustomOAuth2Exception.ACCOUNT_CANCEL:
|
||||
status = OAuthStatus.ACCOUNT_CANCEL;
|
||||
status = BusiStatus.ACCOUNT_CANCEL;
|
||||
break;
|
||||
case CustomOAuth2Exception.ACCOUNT_CANCEL_INFO_NOT_EXIST:
|
||||
status = OAuthStatus.ACCOUNT_CANCEL_INFO_NOT_EXIST;
|
||||
status = BusiStatus.ACCOUNT_CANCEL_INFO_NOT_EXIST;
|
||||
break;
|
||||
case CustomOAuth2Exception.PWD_WRONG_OVER_LIMIT:
|
||||
status = OAuthStatus.PWD_WRONG_OVER_LIMIT;
|
||||
status = BusiStatus.PWD_WRONG_OVER_LIMIT;
|
||||
break;
|
||||
default:
|
||||
status = OAuthStatus.UNKNOWN;
|
||||
status = BusiStatus.UNKNOWN;
|
||||
break;
|
||||
}
|
||||
if (StringUtils.isBlank(reasonPhrase)) {
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.accompany.oauth2.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.common.constant.AppEnum;
|
||||
import com.accompany.common.constant.ApplicationConstant;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
@@ -20,7 +19,6 @@ import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.user.PhoneBlackService;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.accompany.oauth2.model.AccountDetails;
|
||||
import com.accompany.oauth2.service.account.AccountBlockCheckService;
|
||||
@@ -85,7 +83,7 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
|
||||
}
|
||||
if (account == null) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.USER_NOT_EXISTED,
|
||||
OAuthStatus.USER_NOT_EXISTED.getReasonPhrase());
|
||||
BusiStatus.USER_NOT_EXISTED.getReasonPhrase());
|
||||
}
|
||||
return new AccountDetails(account);
|
||||
}
|
||||
@@ -102,7 +100,7 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
|
||||
}
|
||||
if (account == null) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.USER_NOT_EXISTED,
|
||||
OAuthStatus.USER_NOT_EXISTED.getReasonPhrase());
|
||||
BusiStatus.USER_NOT_EXISTED.getReasonPhrase());
|
||||
}
|
||||
return new AccountDetails(account);
|
||||
}
|
||||
@@ -112,7 +110,7 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
|
||||
Account account = accountManageService.getOrGenAccountByOpenid(openid, type, deviceInfo, ipAddress, unionId);
|
||||
if (account == null) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.USER_NOT_EXISTED,
|
||||
OAuthStatus.USER_NOT_EXISTED.getReasonPhrase());
|
||||
BusiStatus.USER_NOT_EXISTED.getReasonPhrase());
|
||||
}
|
||||
return new AccountDetails(account);
|
||||
}
|
||||
@@ -272,7 +270,7 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
|
||||
String countValue = jedisService.hget(cacheKey, username);
|
||||
Long currCount = com.accompany.common.utils.StringUtils.isBlank(countValue) ? 0L : Long.parseLong(countValue);
|
||||
if (currCount >= maxCount) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PWD_WRONG_OVER_LIMIT, OAuthStatus.PWD_WRONG_OVER_LIMIT.getReasonPhrase());
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PWD_WRONG_OVER_LIMIT, BusiStatus.PWD_WRONG_OVER_LIMIT.getReasonPhrase());
|
||||
}
|
||||
if (!password.equals(userDetails.getPassword())) {
|
||||
currCount = jedisService.hincrBy(cacheKey, username, 1L);
|
||||
@@ -280,7 +278,7 @@ public class MyUserDetailsServiceImpl implements MyUserDetailsService {
|
||||
jedisService.expire(cacheKey, 10 * 60);//10分钟后解锁
|
||||
}
|
||||
if (currCount >= maxCount) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PWD_WRONG_OVER_LIMIT, OAuthStatus.PWD_WRONG_OVER_LIMIT.getReasonPhrase());
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PWD_WRONG_OVER_LIMIT, BusiStatus.PWD_WRONG_OVER_LIMIT.getReasonPhrase());
|
||||
} else {
|
||||
Long remainCount = maxCount - currCount;
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PASSWORD_ERROR, String.format(BusiStatus.PASSWORD_ERROR_COUNT.getReasonPhrase(), remainCount));
|
||||
|
@@ -1,35 +1,19 @@
|
||||
package com.accompany.oauth2.service.account;
|
||||
|
||||
import com.accompany.common.constant.ApplicationConstant;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.exception.ApiException;
|
||||
import com.accompany.common.exception.BusinessException;
|
||||
import com.accompany.core.exception.AdminServiceException;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.CommonUtil;
|
||||
import com.accompany.common.utils.UUIDUtil;
|
||||
import com.accompany.core.base.SpringContextHolder;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Account;
|
||||
import com.accompany.core.model.AccountH5LoginRecord;
|
||||
import com.accompany.core.mybatismapper.AccountH5LoginRecordMapper;
|
||||
import com.accompany.core.mybatismapper.AccountLoginRecordMapperExpand;
|
||||
import com.accompany.core.service.account.AccountService;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.util.JwtUtils;
|
||||
import com.accompany.oauth2.support.h5.H5TokenGranter;
|
||||
import com.accompany.oauth2.token.H5AccessToken;
|
||||
import com.accompany.sms.service.SmsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -41,127 +25,13 @@ public class AccountH5LoginService {
|
||||
|
||||
private static final long H5_JWT_TOKEN_EX = 60 * 60 * 1000 * 2L;
|
||||
|
||||
/**
|
||||
* code有效时间为10分钟
|
||||
**/
|
||||
private static final int CODE_EXPIRE_TIME = 60 * 10;
|
||||
|
||||
@Autowired
|
||||
private AccountH5LoginRecordMapper accountH5LoginRecordMapper;
|
||||
@Autowired
|
||||
private AccountLoginRecordMapperExpand accountLoginRecordMapperExpand;
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
@Autowired
|
||||
private AccountService accountService;
|
||||
@Autowired
|
||||
private AccountBlockCheckService accountBlockCheckService;
|
||||
@Autowired
|
||||
private SmsService smsService;
|
||||
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
|
||||
@Autowired
|
||||
private AccountManageService accountManageService;
|
||||
|
||||
public AccountH5LoginRecord buildRecord(Long uid, Byte loginType, String ip, String os, String appVersion, String deviceId) {
|
||||
AccountH5LoginRecord accountH5LoginRecord = new AccountH5LoginRecord();
|
||||
accountH5LoginRecord.setUid(uid);
|
||||
accountH5LoginRecord.setIp(ip);
|
||||
accountH5LoginRecord.setOs(os);
|
||||
accountH5LoginRecord.setAppVersion(appVersion);
|
||||
accountH5LoginRecord.setDeviceId(deviceId);
|
||||
accountH5LoginRecord.setLoginType(loginType);
|
||||
accountH5LoginRecord.setCreateTime(new Date());
|
||||
return accountH5LoginRecord;
|
||||
}
|
||||
|
||||
@Async
|
||||
public void insertRecord(AccountH5LoginRecord accountH5LoginRecord) {
|
||||
accountH5LoginRecordMapper.insert(accountH5LoginRecord);
|
||||
}
|
||||
|
||||
//获取授权码
|
||||
public String getAuthCode() {
|
||||
String code = UUIDUtil.get();
|
||||
// 设置code至缓存且设置有效期
|
||||
jedisService.write(RedisKey.h5_login_code.getKey(code), "null", CODE_EXPIRE_TIME);
|
||||
return code;
|
||||
}
|
||||
|
||||
public String checkCodeIsUsed(String code) throws Exception {
|
||||
String key = RedisKey.h5_login_code.getKey(code);
|
||||
Boolean codeIsExist = jedisService.exits(key);
|
||||
if (!codeIsExist) {
|
||||
throw new BusinessException(BusiStatus.CODE_ILLEGAL.getReasonPhrase());
|
||||
}
|
||||
String token = jedisService.get(key);
|
||||
if (StringUtils.isEmpty(token) || ApplicationConstant.NULL_JSON_OBJECT.equals(token)) {
|
||||
return null;
|
||||
} else {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权登录
|
||||
*
|
||||
* @param code
|
||||
* @param uid
|
||||
*/
|
||||
public void h5AuthLogin(String code, Long uid, String ip, String os, String appVersion, String deviceId) throws Exception {
|
||||
String loginToken = UUIDUtil.get();
|
||||
jedisService.set(RedisKey.h5_login_code.getKey(code), loginToken);
|
||||
jedisService.write(RedisKey.h5_login_token.getKey(loginToken), uid.toString(), CODE_EXPIRE_TIME);
|
||||
AccountH5LoginRecord accountH5LoginRecord = this.buildRecord(uid, Constant.LoginAppType.ExchangeSys, ip, os, appVersion, deviceId);
|
||||
this.insertRecord(accountH5LoginRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* h5登录
|
||||
*
|
||||
* @param token
|
||||
*/
|
||||
public Map<String, String> h5Login(String token) throws Exception {
|
||||
String uidStr = jedisService.get(RedisKey.h5_login_token.getKey(token));
|
||||
if (StringUtils.isEmpty(uidStr)) {
|
||||
throw new ApiException(BusiStatus.USERNOTEXISTS);
|
||||
}
|
||||
Long uid = Long.valueOf(uidStr);
|
||||
Account account = accountService.getById(uid);
|
||||
if (account == null) {
|
||||
throw new ApiException(BusiStatus.ACCOUNT_NOT_EXISTS);
|
||||
}
|
||||
accountBlockCheckService.checkBlockedAccount(account);
|
||||
String jwtToken = createJwtToken(uid);
|
||||
jedisService.hset(RedisKey.h5loginjwtoken.getKey(), account.getUid().toString(), jwtToken);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("uid", uid.toString());
|
||||
map.put("token", jwtToken);
|
||||
return map;
|
||||
}
|
||||
|
||||
public Map<String, String> smsLogin(String mobile, String code) {
|
||||
// 校验验证码
|
||||
if (!smsService.verifySmsCode(mobile, code)) {
|
||||
throw new ServiceException(BusiStatus.SMSCODEERROR);
|
||||
}
|
||||
Account account = accountService.getAccountByPhone(mobile);
|
||||
if (null == account) {
|
||||
throw new ApiException(BusiStatus.ACCOUNT_NOT_EXISTS);
|
||||
}
|
||||
accountBlockCheckService.checkBlockedAccount(account);
|
||||
// 生成jwtToken
|
||||
Long uid = account.getUid();
|
||||
String jwtToken = createJwtToken(account.getUid());
|
||||
saveH5LoginJwtToken(uid, jwtToken);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("uid", account.getUid().toString());
|
||||
map.put("token", jwtToken);
|
||||
return map;
|
||||
}
|
||||
|
||||
public String createJwtToken(Long uid) {
|
||||
return jwtUtils.createJWT(H5_JWT_TOKEN_EX, uid);
|
||||
}
|
||||
@@ -174,26 +44,6 @@ public class AccountH5LoginService {
|
||||
jedisService.hdel(RedisKey.h5loginjwtoken.getKey(), uid.toString());
|
||||
}
|
||||
|
||||
public void register(String mobile, String code, String inviteCode, Long inviteUid, DeviceInfo deviceInfo, String ipAddress, String phoneAreaCode) {
|
||||
// 校验验证码
|
||||
if (!smsService.verifySmsCode(mobile, code)) {
|
||||
throw new ServiceException(BusiStatus.SMSCODEERROR);
|
||||
}
|
||||
Account account = accountService.getAccountByPhone(mobile);
|
||||
if (null != account) {
|
||||
throw new ServiceException(BusiStatus.PHONE_REGISTERED);
|
||||
}
|
||||
if (!CommonUtil.checkPhoneFormat(phoneAreaCode, mobile)) {
|
||||
throw new ServiceException(BusiStatus.PHONEINVALID);
|
||||
}
|
||||
try {
|
||||
accountManageService.saveSignUpByPhone(mobile, null, deviceInfo, inviteCode, inviteUid, ipAddress, phoneAreaCode);
|
||||
} catch (Exception e) {
|
||||
log.error("h5 注册失败。mobile:{}", mobile);
|
||||
throw new ServiceException(BusiStatus.H5_REGISTER_ERROR.getReasonPhrase(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建h5令牌
|
||||
*
|
||||
@@ -227,7 +77,7 @@ public class AccountH5LoginService {
|
||||
Integer isExists = accountLoginRecordMapperExpand.isExists(uid);
|
||||
if (isExists > 0) {
|
||||
deleteH5LoginJwtToken(uid);
|
||||
throw new ApiException(BusiStatus.REGION_NOT_OPEN_UP);
|
||||
throw new AdminServiceException(BusiStatus.REGION_NOT_OPEN_UP);
|
||||
}
|
||||
}
|
||||
return token;
|
||||
|
@@ -3,7 +3,6 @@ package com.accompany.oauth2.service.account;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.exception.BusinessException;
|
||||
import com.accompany.common.netease.neteaseacc.result.TokenRet;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
@@ -25,9 +24,7 @@ import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.user.UserCancelRecordService;
|
||||
import com.accompany.core.service.user.UsersBaseService;
|
||||
import com.accompany.core.util.MD5;
|
||||
import com.accompany.core.vo.VisitorVo;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
import com.accompany.oauth2.dto.IpMaxRegisterLimitConfig;
|
||||
import com.accompany.oauth2.event.UserRegisterSuccessEvent;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
@@ -279,32 +276,6 @@ public class AccountManageService {
|
||||
return account;
|
||||
}
|
||||
|
||||
public VisitorVo genVisitorAccount() throws Exception {
|
||||
String password = "visitoradmin999";
|
||||
Date date = new Date();
|
||||
Account account = new Account();
|
||||
account.setErbanNo(Constant.Visitor.visitorErbanNo);
|
||||
account.setPassword(encryptPassword(password));
|
||||
account.setNeteaseToken(UUIDUtil.get());
|
||||
account.setLastLoginTime(date);
|
||||
account.setUpdateTime(date);
|
||||
account.setSignTime(date);
|
||||
accountMapper.insert(account);
|
||||
accountService.writeAche(account);
|
||||
String uidStr = String.valueOf(account.getUid());
|
||||
TokenRet tokenRet = netEaseService.createNetEaseAcc(uidStr, account.getNeteaseToken(), "");
|
||||
if (tokenRet.getCode() != BusiStatus.SUCCESS.value()) {
|
||||
log.error("获取游客账号异常code=" + tokenRet.getCode());
|
||||
throw new BusinessException("获取游客账号异常code=注册异常,异常原因code=" + tokenRet.getCode());
|
||||
}
|
||||
VisitorVo visitorVo = new VisitorVo();
|
||||
visitorVo.setUid(account.getUid());
|
||||
visitorVo.setNetEaseToken(account.getNeteaseToken());
|
||||
visitorVo.setGender(new Byte("1"));
|
||||
visitorVo.setNick("游客");
|
||||
return visitorVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* 两个场景调用 => 客户端未登录 忘记密码, 此时uid 为 null 登录状态下忘记密码 uid有值
|
||||
@@ -318,28 +289,28 @@ public class AccountManageService {
|
||||
if (phone.contains("*")) {
|
||||
Account account = accountService.getById(uid);
|
||||
if (account == null) {
|
||||
throw new ServiceException(OAuthStatus.USER_NOT_EXISTED);
|
||||
throw new ServiceException(BusiStatus.USER_NOT_EXISTED);
|
||||
}
|
||||
phone = account.getPhone();
|
||||
if (!CommonUtil.checkPhoneFormat(account.getPhoneAreaCode(),account.getPhone())) {
|
||||
throw new ServiceException(OAuthStatus.ACCOUNT_NOT_BIND_PHONE);
|
||||
throw new ServiceException(BusiStatus.ACCOUNT_NOT_BIND_PHONE);
|
||||
}
|
||||
}
|
||||
|
||||
int count = accountService.countByPhone(phone);
|
||||
if (count > 1) {
|
||||
throw new ServiceException(OAuthStatus.PHONE_BIND_TOO_MANY_ACCOUNT);
|
||||
throw new ServiceException(BusiStatus.PHONE_BIND_TOO_MANY_ACCOUNT);
|
||||
}
|
||||
|
||||
Account account = accountService.getAccountByPhone(phone);
|
||||
if (null == account || (uid != null && !account.getUid().equals(uid)) ) {
|
||||
throw new ServiceException(OAuthStatus.PHONE_BIND_ERROR);
|
||||
throw new ServiceException(BusiStatus.PHONE_BIND_ERROR);
|
||||
}
|
||||
|
||||
uid = account.getUid();
|
||||
//检验验证码
|
||||
if (!accountService.verifySmsCodeByCache(phone, resetCode, uid)){
|
||||
throw new ServiceException(OAuthStatus.INVALID_IDENTIFYING_CODE);
|
||||
throw new ServiceException(BusiStatus.INVALID_IDENTIFYING_CODE);
|
||||
}
|
||||
|
||||
accountService.resetAccountPwd(account.getUid(), password);
|
||||
@@ -355,13 +326,13 @@ public class AccountManageService {
|
||||
public void resetPasswordByOldPassword(String phone, String password, String newPassword) {
|
||||
Account account = accountService.getAccountByPhone(phone);
|
||||
if (null == account) {
|
||||
throw new ServiceException(OAuthStatus.USER_NOT_EXISTED);
|
||||
throw new ServiceException(BusiStatus.USER_NOT_EXISTED);
|
||||
}
|
||||
|
||||
String oldPwd = account.getPassword();
|
||||
password = encryptPassword(password);
|
||||
if (!StringUtils.hasText(password) || !password.equals(oldPwd)){
|
||||
throw new ServiceException(OAuthStatus.OLD_PASSWORD_ERROR);
|
||||
throw new ServiceException(BusiStatus.OLD_PASSWORD_ERROR);
|
||||
}
|
||||
|
||||
accountService.resetAccountPwd(account.getUid(), newPassword);
|
||||
@@ -381,12 +352,12 @@ public class AccountManageService {
|
||||
public void setupInitialPassword(Long uid, String password) {
|
||||
Account account = accountService.getById(uid);
|
||||
if (account == null) {
|
||||
throw new ServiceException(OAuthStatus.INVALID_USER);
|
||||
throw new ServiceException(BusiStatus.INVALID_USER);
|
||||
}
|
||||
|
||||
Boolean result = accountService.updateAccountPwd(account.getUid(), password);
|
||||
if (!result){
|
||||
throw new ServiceException(OAuthStatus.INVALID_REQUEST);
|
||||
throw new ServiceException(BusiStatus.INVALID_REQUEST);
|
||||
}
|
||||
|
||||
// 更新用户缓存
|
||||
@@ -410,12 +381,12 @@ public class AccountManageService {
|
||||
if (ObjectUtil.isNull(userCancelRecord)) {
|
||||
//获取不到注销账号信息
|
||||
log.info("获取不到用户{}注销信息", uid);
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.ACCOUNT_CANCEL_INFO_NOT_EXIST, OAuthStatus.ACCOUNT_CANCEL_INFO_NOT_EXIST.getReasonPhrase());
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.ACCOUNT_CANCEL_INFO_NOT_EXIST, BusiStatus.ACCOUNT_CANCEL_INFO_NOT_EXIST.getReasonPhrase());
|
||||
}
|
||||
|
||||
|
||||
log.info("检测到注销账号{}昵称{}于{}尝试登录", users.getErbanNo(), userCancelRecord.getNick(), DateTimeUtil.convertDate(userCancelRecord.getUpdateTime()));
|
||||
CustomOAuth2Exception exception = new CustomOAuth2Exception(CustomOAuth2Exception.ACCOUNT_CANCEL, OAuthStatus.ACCOUNT_CANCEL.getReasonPhrase());
|
||||
CustomOAuth2Exception exception = new CustomOAuth2Exception(CustomOAuth2Exception.ACCOUNT_CANCEL, BusiStatus.ACCOUNT_CANCEL.getReasonPhrase());
|
||||
exception.addAdditionalInformation("erbanNo", String.valueOf(users.getErbanNo()));
|
||||
exception.addAdditionalInformation("cancelDate", String.valueOf(userCancelRecord.getUpdateTime().getTime()));
|
||||
exception.addAdditionalInformation("nick", userCancelRecord.getNick());
|
||||
|
@@ -2,7 +2,7 @@ package com.accompany.oauth2.support.h5;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.exception.ApiException;
|
||||
import com.accompany.core.exception.AdminServiceException;
|
||||
import com.accompany.common.utils.DESUtils;
|
||||
import com.accompany.core.util.KeyStore;
|
||||
import com.accompany.core.util.MD5;
|
||||
@@ -63,7 +63,7 @@ public class PasswordH5TokenGranter extends AbstractH5TokenGranter {
|
||||
userDetailsService.login(username, userDetails, LoginTypeEnum.PASSWORD, deviceInfo, code);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new ApiException(e.getMessage());
|
||||
throw new AdminServiceException(e.getMessage());
|
||||
}
|
||||
return accountH5LoginService.createH5AccessToken(((AccountDetails) userDetails).getAccount().getUid());
|
||||
}
|
||||
|
@@ -2,11 +2,11 @@ package com.accompany.oauth2.support.h5;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.exception.ApiException;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.core.exception.AdminServiceException;
|
||||
import com.accompany.core.service.user.PhoneBlackService;
|
||||
import com.accompany.oauth2.constant.GrantTypeEnum;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.accompany.oauth2.model.AccountDetails;
|
||||
import com.accompany.oauth2.service.MyUserDetailsService;
|
||||
@@ -52,7 +52,7 @@ public class VerifyCodeH5TokenGranter extends AbstractH5TokenGranter {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
if (phoneBlackService.checkIsNeedIntercept(phone)) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PHONE_BE_INTERCEPTED, OAuthStatus.PHONE_BE_INTERCEPTED.getReasonPhrase());
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PHONE_BE_INTERCEPTED, BusiStatus.PHONE_BE_INTERCEPTED.getReasonPhrase());
|
||||
}
|
||||
UserDetails userDetails = null;
|
||||
try {
|
||||
@@ -62,7 +62,7 @@ public class VerifyCodeH5TokenGranter extends AbstractH5TokenGranter {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new ApiException(e.getMessage());
|
||||
throw new AdminServiceException(e.getMessage());
|
||||
}
|
||||
return accountH5LoginService.createH5AccessToken(((AccountDetails) userDetails).getAccount().getUid());
|
||||
}
|
||||
|
@@ -2,19 +2,17 @@ package com.accompany.oauth2.support.password;
|
||||
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.AppVersionUtil;
|
||||
import com.accompany.common.utils.DESUtils;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.user.PhoneBlackService;
|
||||
import com.accompany.core.util.KeyStore;
|
||||
import com.accompany.core.util.MD5;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.accompany.oauth2.service.MyUserDetailsService;
|
||||
import com.accompany.oauth2.service.account.AccountH5LoginService;
|
||||
import com.accompany.oauth2.util.RequestContextHolderUtils;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -46,12 +44,6 @@ public class PasswordAuthenticationProvider implements AuthenticationProvider {
|
||||
@Autowired
|
||||
private PhoneBlackService phoneBlackService;
|
||||
|
||||
@Autowired
|
||||
private AccountH5LoginService accountH5LoginService;
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
|
||||
public PasswordAuthenticationProvider(MyUserDetailsService myUserDetailsService, SysConfService sysConfService) {
|
||||
this.myUserDetailsService = myUserDetailsService;
|
||||
this.sysConfService = sysConfService;
|
||||
@@ -79,7 +71,7 @@ public class PasswordAuthenticationProvider implements AuthenticationProvider {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.ACCOUNT_ERROR,
|
||||
OAuthStatus.ACCOUNT_ERROR.getReasonPhrase());
|
||||
BusiStatus.ACCOUNT_ERROR.getReasonPhrase());
|
||||
}
|
||||
String password = (String) authentication.getCredentials();
|
||||
LoginTypeEnum loginTypeEnum = null;
|
||||
@@ -91,11 +83,11 @@ public class PasswordAuthenticationProvider implements AuthenticationProvider {
|
||||
// 低于1.5版本不能进行登录
|
||||
String limitAppVersion = sysConfService.getDefaultSysConfValueById(Constant.SysConfId.APP_VERSION_LIMIT, Constant.LOWEST_VERSION_FOR_USE);
|
||||
if (deviceInfo.getAppVersion() == null || AppVersionUtil.compareVersion(deviceInfo.getAppVersion(), limitAppVersion) < 0) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.APP_VERSION_TOO_OLD, OAuthStatus.APP_VERSION_TOO_OLD.getReasonPhrase());
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.APP_VERSION_TOO_OLD, BusiStatus.APP_VERSION_TOO_OLD.getReasonPhrase());
|
||||
}
|
||||
if (phoneBlackService.checkIsNeedIntercept(username)) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PHONE_BE_INTERCEPTED,
|
||||
OAuthStatus.PHONE_BE_INTERCEPTED.getReasonPhrase());
|
||||
BusiStatus.PHONE_BE_INTERCEPTED.getReasonPhrase());
|
||||
}
|
||||
UserDetails userDetails;
|
||||
try {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package com.accompany.oauth2.support.verify;
|
||||
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.core.service.user.PhoneBlackService;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.accompany.oauth2.service.MyUserDetailsService;
|
||||
import com.accompany.oauth2.util.RequestContextHolderUtils;
|
||||
@@ -49,7 +49,7 @@ public class VerifyCodeAuthenticationProvider implements AuthenticationProvider
|
||||
log.error("populate deviceInfo fail", e);
|
||||
}
|
||||
if (phoneBlackService.checkIsNeedIntercept(phone)) {
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PHONE_BE_INTERCEPTED, OAuthStatus.PHONE_BE_INTERCEPTED.getReasonPhrase());
|
||||
throw new CustomOAuth2Exception(CustomOAuth2Exception.PHONE_BE_INTERCEPTED, BusiStatus.PHONE_BE_INTERCEPTED.getReasonPhrase());
|
||||
}
|
||||
UserDetails userDetails = null;
|
||||
try {
|
||||
|
@@ -66,7 +66,7 @@ public class BaseController {
|
||||
try {
|
||||
desInfo = DESUtils.DESAndBase64Decrypt(sensitiveInfo, KeyStore.DES_ENCRYPT_KEY);
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(BusiStatus.SERVER_BUSY);
|
||||
throw new ServiceException(BusiStatus.SERVERBUSY);
|
||||
}
|
||||
return desInfo;
|
||||
}
|
||||
|
@@ -2,17 +2,13 @@ package com.accompany.oauth2.controller;
|
||||
|
||||
import com.accompany.common.constant.AppEnum;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.exception.BusinessException;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.*;
|
||||
import com.accompany.oauth2.common.BaseController;
|
||||
import com.accompany.oauth2.config.OAuthConfig;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
import com.accompany.oauth2.model.AccountDetails;
|
||||
import com.accompany.oauth2.result.ServiceRes;
|
||||
import com.accompany.oauth2.service.MyUserDetailsService;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -44,12 +40,12 @@ public class AccountController extends BaseController {
|
||||
|
||||
@PostMapping("/logout")
|
||||
@ResponseBody
|
||||
public ServiceRes<Void> logout(@RequestParam("access_token") String token) {
|
||||
public BusiResult<Void> logout(@RequestParam("access_token") String token) {
|
||||
if (StringUtils.isBlank(token)) {
|
||||
return new ServiceRes<>(OAuthStatus.INVALID_REQUEST);
|
||||
return new BusiResult<>(BusiStatus.INVALID_REQUEST);
|
||||
}
|
||||
myUserDetailsService.logout(token);
|
||||
return new ServiceRes<>(OAuthStatus.SUCCESS);
|
||||
return BusiResult.success();
|
||||
}
|
||||
|
||||
@RequestMapping("/third/login")
|
||||
|
@@ -1,28 +1,18 @@
|
||||
package com.accompany.oauth2.controller;
|
||||
|
||||
import com.accompany.common.annotation.Authorization;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.exception.ApiException;
|
||||
import com.accompany.common.exception.BusinessException;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.IPUtils;
|
||||
import com.accompany.common.utils.StringUtils;
|
||||
import com.accompany.oauth2.common.BaseController;
|
||||
import com.accompany.oauth2.exception.CustomOAuth2Exception;
|
||||
import com.accompany.oauth2.service.account.AccountH5LoginService;
|
||||
import com.accompany.oauth2.token.H5AccessToken;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by yuanyi on 2019/2/22.
|
||||
@@ -35,96 +25,6 @@ public class H5LoginController extends BaseController {
|
||||
@Autowired
|
||||
private AccountH5LoginService accountH5LoginService;
|
||||
|
||||
/**
|
||||
* app授权登录
|
||||
*
|
||||
* @param request
|
||||
* @param code
|
||||
* @param uid
|
||||
* @return
|
||||
*/
|
||||
@Authorization
|
||||
@RequestMapping(value = "/authorized/login", method = RequestMethod.POST)
|
||||
public BusiResult<Void> loginAuthorizedByH5(HttpServletRequest request, @RequestParam String code, @RequestParam Long uid, @RequestBody DeviceInfo deviceInfo) {
|
||||
log.info("h5 authorized login params is: code={},uid={},deviceInfo={}", code, uid, JSONObject.toJSON(deviceInfo));
|
||||
try {
|
||||
String ip = IPUtils.getRealIpAddress(request);
|
||||
this.accountH5LoginService.h5AuthLogin(code, uid, ip, deviceInfo.getOs(), deviceInfo.getAppVersion(), deviceInfo.getDeviceId());
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
} catch (CustomOAuth2Exception e) {
|
||||
return new BusiResult<>(BusiStatus.ACCOUNT_ERROR);
|
||||
} catch (BusinessException e) {
|
||||
return new BusiResult<>(BusiStatus.SERVERERROR, e.getMessage(), null);
|
||||
} catch (Exception e) {
|
||||
log.error("h5 authorized login failed,param is: code={},uid={},deviceInfo={}", code, uid, JSONObject.toJSON(deviceInfo), e);
|
||||
return new BusiResult<>(BusiStatus.BUSIERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取授权码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/code/get")
|
||||
public BusiResult<String> getAuthCode() {
|
||||
String code = this.accountH5LoginService.getAuthCode();
|
||||
return new BusiResult<>(BusiStatus.SUCCESS, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/code/check")
|
||||
public BusiResult<String> checkCodeIsUsed(String code) {
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
return new BusiResult<>(BusiStatus.PARAMERROR);
|
||||
}
|
||||
try {
|
||||
String token = this.accountH5LoginService.checkCodeIsUsed(code);
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
return new BusiResult<>(BusiStatus.SERVERERROR);
|
||||
}
|
||||
return new BusiResult<>(BusiStatus.SUCCESS, token);
|
||||
} catch (BusinessException e) {
|
||||
return new BusiResult<>(BusiStatus.SERVERERROR, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return new BusiResult<>(BusiStatus.BUSIERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/login")
|
||||
public BusiResult<Map<String, String>> loginByToken(String token) {
|
||||
try {
|
||||
Map<String, String> map = this.accountH5LoginService.h5Login(token);
|
||||
log.info("h5 login ...... token={},result={}", token, JSONObject.toJSON(map));
|
||||
return new BusiResult<>(BusiStatus.SUCCESS, map);
|
||||
} catch (CustomOAuth2Exception e) {
|
||||
return new BusiResult<>(BusiStatus.ACCOUNT_ERROR);
|
||||
} catch (Exception e) {
|
||||
log.error("h5 login failed,token={}", token, e);
|
||||
return new BusiResult<>(BusiStatus.BUSIERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机验证码H5登录
|
||||
*
|
||||
* @param mobile
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/smsLogin")
|
||||
public BusiResult<Map<String, String>> loginBySms(String mobile, String code) {
|
||||
log.info("h5 smsLogin, mobile:{}, code:{}", mobile, code);
|
||||
return new BusiResult<>(accountH5LoginService.smsLogin(mobile, code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权登录
|
||||
*
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.accompany.oauth2.controller;
|
||||
|
||||
import com.accompany.common.annotation.Authorization;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.DESUtils;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
@@ -8,14 +9,11 @@ import com.accompany.core.model.Account;
|
||||
import com.accompany.core.service.account.AccountService;
|
||||
import com.accompany.core.util.KeyStore;
|
||||
import com.accompany.oauth2.common.BaseController;
|
||||
import com.accompany.oauth2.constant.OAuthStatus;
|
||||
import com.accompany.oauth2.result.ServiceRes;
|
||||
import com.accompany.oauth2.service.account.AccountManageService;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -45,7 +43,7 @@ public class PwdController extends BaseController {
|
||||
//@Authorization
|
||||
@PostMapping("/reset")
|
||||
@SneakyThrows
|
||||
public ServiceRes<Void> resetPassword(HttpServletRequest request,
|
||||
public BusiResult<Void> resetPassword(HttpServletRequest request,
|
||||
String phone, String newPwd, String smsCode) {
|
||||
if (StringUtils.isBlank(phone) || StringUtils.isBlank(newPwd) || StringUtils.isBlank(smsCode)){
|
||||
throw new ServiceException(BusiStatus.PARAMERROR);
|
||||
@@ -57,24 +55,23 @@ public class PwdController extends BaseController {
|
||||
|
||||
// 密码长度检查
|
||||
if(!newPwd.matches(PASSWORD_REGIX_V2)){
|
||||
return new ServiceRes<>(OAuthStatus.WEAK_PASSWORD);
|
||||
return new BusiResult<>(BusiStatus.WEAK_PASSWORD);
|
||||
}
|
||||
|
||||
accountManageService.resetPasswordByResetCode(uid, phone, newPwd, smsCode);
|
||||
|
||||
return new ServiceRes<>(OAuthStatus.SUCCESS);
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置新密码
|
||||
* @param uid
|
||||
* @param newPwd
|
||||
* @return
|
||||
*/
|
||||
@Authorization
|
||||
@PostMapping("/set")
|
||||
@SneakyThrows
|
||||
public ServiceRes<Void> setupPassword(HttpServletRequest request, String newPwd) {
|
||||
public BusiResult<Void> setupPassword(HttpServletRequest request, String newPwd) {
|
||||
Long uid = getUid(request);
|
||||
|
||||
//加入密码DES解密
|
||||
@@ -82,18 +79,18 @@ public class PwdController extends BaseController {
|
||||
|
||||
// 密码长度检查
|
||||
if(!newPwd.matches(PASSWORD_REGIX_V2)){
|
||||
return new ServiceRes<>(OAuthStatus.WEAK_PASSWORD);
|
||||
return new BusiResult<>(BusiStatus.WEAK_PASSWORD);
|
||||
}
|
||||
|
||||
accountManageService.setupInitialPassword(uid, newPwd);
|
||||
|
||||
return new ServiceRes<>(OAuthStatus.SUCCESS);
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
@Authorization
|
||||
@PostMapping("/modify")
|
||||
@SneakyThrows
|
||||
public ServiceRes<Void> modifyPassword(HttpServletRequest request,
|
||||
public BusiResult<Void> modifyPassword(HttpServletRequest request,
|
||||
String pwd, String newPwd) {
|
||||
|
||||
Long uid = getUid(request);
|
||||
@@ -104,17 +101,17 @@ public class PwdController extends BaseController {
|
||||
|
||||
// 密码长度检查
|
||||
if(!newPwd.matches(PASSWORD_REGIX_V2)){
|
||||
return new ServiceRes<>(OAuthStatus.WEAK_PASSWORD);
|
||||
return new BusiResult<>(BusiStatus.WEAK_PASSWORD);
|
||||
}
|
||||
|
||||
Account account = this.accountService.getById(uid);
|
||||
if (account == null) {
|
||||
return new ServiceRes<>(OAuthStatus.INVALID_USER);
|
||||
return new BusiResult<>(BusiStatus.INVALID_USER);
|
||||
}
|
||||
|
||||
accountManageService.resetPasswordByOldPassword(account.getPhone(), pwd, newPwd);
|
||||
|
||||
return new ServiceRes<>(OAuthStatus.SUCCESS);
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user