|
|
@@ -1,10 +1,8 @@
|
|
|
package com.zhiqiyun.open.mvc.controller;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.dliyun.Response;
|
|
|
import com.zhiqiyun.open.annotation.Permission;
|
|
|
import com.zhiqiyun.open.core.enmus.AccountType;
|
|
|
import com.zhiqiyun.open.core.enmus.PasswordType;
|
|
|
@@ -16,10 +14,7 @@ import com.zhiqiyun.open.mvc.params.ChangePasswordParam;
|
|
|
import com.zhiqiyun.open.mvc.params.LoginParam;
|
|
|
import com.zhiqiyun.open.mvc.params.QueryPageParams;
|
|
|
import com.zhiqiyun.open.mvc.params.SaveUserBaseInfoParam;
|
|
|
-import com.zhiqiyun.open.utils.DateUtil;
|
|
|
-import com.zhiqiyun.open.utils.RandomUtil;
|
|
|
-import com.zhiqiyun.open.utils.ServletContext;
|
|
|
-import com.zhiqiyun.open.utils.Token;
|
|
|
+import com.zhiqiyun.open.utils.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
@@ -52,8 +47,8 @@ public class OauthController {
|
|
|
@Autowired
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
|
|
|
- @Autowired
|
|
|
- private UnifiedLoginService unifiedLoginService;
|
|
|
+// @Autowired
|
|
|
+// private UnifiedLoginService unifiedLoginService;
|
|
|
|
|
|
@PostMapping("/getCaptcha")
|
|
|
public Result captcha() {
|
|
|
@@ -79,13 +74,13 @@ public class OauthController {
|
|
|
public Result login(@Valid @RequestBody LoginParam loginParam) {
|
|
|
UserLoginLog userLoginLog = new UserLoginLog();
|
|
|
try {
|
|
|
-// AccountType accountType = null;
|
|
|
-// if (PatternUtils.validExpression(loginParam.getLoginAccount(), PatternUtils.MOBILE_EXPRESSION)) {
|
|
|
-// accountType = AccountType.mp;
|
|
|
-// }
|
|
|
-// if (PatternUtils.validExpression(loginParam.getLoginAccount(), PatternUtils.EMAIL_EXPRESSION)) {
|
|
|
-// accountType = AccountType.email;
|
|
|
-// }
|
|
|
+ AccountType accountType = null;
|
|
|
+ if (PatternUtils.validExpression(loginParam.getLoginAccount(), PatternUtils.MOBILE_EXPRESSION)) {
|
|
|
+ accountType = AccountType.mp;
|
|
|
+ }
|
|
|
+ if (PatternUtils.validExpression(loginParam.getLoginAccount(), PatternUtils.EMAIL_EXPRESSION)) {
|
|
|
+ accountType = AccountType.email;
|
|
|
+ }
|
|
|
userLoginLog.setLoginAccount(loginParam.getLoginAccount());
|
|
|
|
|
|
boolean compareCaptchaResult = this.captchaService.compareCaptcha(loginParam.getCaptcha(), loginParam.getToken(), true);
|
|
|
@@ -93,48 +88,50 @@ public class OauthController {
|
|
|
userLoginLog.setState(UserLoginLogState.CAPTCHA_ERROR);
|
|
|
return Result.instance("验证码错误,请重新输入");
|
|
|
}
|
|
|
-// UserLoginAccount userLoginAccount = this.userBaseInfoService.findLoginAccount(loginParam.getLoginAccount());
|
|
|
-// if (userLoginAccount == null) {
|
|
|
-// userLoginLog.setState(UserLoginLogState.ACCOUNT_NOT_EXIST);
|
|
|
-// return Result.instance("用户名或密码错误,请重新输入");
|
|
|
-// } else {
|
|
|
- Response<JSONObject> response = unifiedLoginService.login(loginParam.getLoginAccount(), loginParam.getLoginPassword());
|
|
|
- if (!response.isSuccessful() || response.getBody() == null) {
|
|
|
+ UserLoginAccount userLoginAccount = this.userBaseInfoService.findLoginAccount(loginParam.getLoginAccount());
|
|
|
+ if (userLoginAccount == null) {
|
|
|
userLoginLog.setState(UserLoginLogState.ACCOUNT_NOT_EXIST);
|
|
|
return Result.instance("用户名或密码错误,请重新输入");
|
|
|
- }
|
|
|
- System.out.println(response.getBody().toJSONString());
|
|
|
- userLoginLog.setAccountType(AccountType.email);
|
|
|
- UserBaseInfo userBaseInfo = this.userBaseInfoService.selectUnified(response.getBody().getLong("user_id"));
|
|
|
-
|
|
|
-// UserPassword userPassword = this.userBaseInfoService.findPassword(userBaseInfo.getId(), PasswordType.login);
|
|
|
-
|
|
|
-// String loginPassword = this.oauthService.generatePassword(loginParam.getLoginPassword(), userPassword.getSalt());
|
|
|
-// if (loginPassword.equals(userPassword.getPasswd())) {
|
|
|
-
|
|
|
- List<String> listAuthorities = this.userBaseInfoService.findUserAuthorities(userBaseInfo.getId());
|
|
|
-
|
|
|
-// String accessToken = Token.init(ServletContext.getRemoteIPAddress()).toTokenString();
|
|
|
- String accessToken = response.getBody().getString("access_token");
|
|
|
- String refreshToken = response.getBody().getString("refresh_token");
|
|
|
- OauthInfo oauthInfo = new OauthInfo()
|
|
|
- .setId(userBaseInfo.getId())
|
|
|
- .setAccessToken(accessToken)
|
|
|
- .setRefreshToken(refreshToken)
|
|
|
- .setNickName(userBaseInfo.getNickName())
|
|
|
- .setAvatar(userBaseInfo.getAvatar())
|
|
|
- .setLoginTime(DateUtil.current())
|
|
|
- .setGender(userBaseInfo.getGender())
|
|
|
- .setAuthorities(listAuthorities);
|
|
|
-
|
|
|
- this.oauthService.setAuth(accessToken, oauthInfo);
|
|
|
- userLoginLog.setState(UserLoginLogState.SUCCESS);
|
|
|
- return Result.instance(Result.Code.SUCCESS).setData(oauthInfo);
|
|
|
-// } else {
|
|
|
-// userLoginLog.setState(UserLoginLogState.PASSWORD_ERROR);
|
|
|
+ } else {
|
|
|
+// Response<JSONObject> response = unifiedLoginService.login(loginParam.getLoginAccount(), loginParam.getLoginPassword());
|
|
|
+// if (!response.isSuccessful() || response.getBody() == null) {
|
|
|
+// userLoginLog.setState(UserLoginLogState.ACCOUNT_NOT_EXIST);
|
|
|
// return Result.instance("用户名或密码错误,请重新输入");
|
|
|
// }
|
|
|
-// }
|
|
|
+// System.out.println(response.getBody().toJSONString());
|
|
|
+// userLoginLog.setAccountType(AccountType.email);
|
|
|
+ userLoginLog.setAccountType(accountType);
|
|
|
+// UserBaseInfo userBaseInfo = this.userBaseInfoService.selectUnified(response.getBody().getLong("user_id"));
|
|
|
+ UserBaseInfo userBaseInfo = this.userBaseInfoService.getById(userLoginAccount.getUid());
|
|
|
+
|
|
|
+ UserPassword userPassword = this.userBaseInfoService.findPassword(userBaseInfo.getId(), PasswordType.login);
|
|
|
+
|
|
|
+ String loginPassword = this.oauthService.generatePassword(loginParam.getLoginPassword(), userPassword.getSalt());
|
|
|
+ if (loginPassword.equals(userPassword.getPasswd())) {
|
|
|
+
|
|
|
+ List<String> listAuthorities = this.userBaseInfoService.findUserAuthorities(userBaseInfo.getId());
|
|
|
+
|
|
|
+ String accessToken = Token.init(ServletContext.getRemoteIPAddress()).toTokenString();
|
|
|
+// String accessToken = response.getBody().getString("access_token");
|
|
|
+// String refreshToken = response.getBody().getString("refresh_token");
|
|
|
+ OauthInfo oauthInfo = new OauthInfo()
|
|
|
+ .setId(userBaseInfo.getId())
|
|
|
+ .setAccessToken(accessToken)
|
|
|
+ .setRefreshToken(accessToken)
|
|
|
+ .setNickName(userBaseInfo.getNickName())
|
|
|
+ .setAvatar(userBaseInfo.getAvatar())
|
|
|
+ .setLoginTime(DateUtil.current())
|
|
|
+ .setGender(userBaseInfo.getGender())
|
|
|
+ .setAuthorities(listAuthorities);
|
|
|
+
|
|
|
+ this.oauthService.setAuth(accessToken, oauthInfo);
|
|
|
+ userLoginLog.setState(UserLoginLogState.SUCCESS);
|
|
|
+ return Result.instance(Result.Code.SUCCESS).setData(oauthInfo);
|
|
|
+ } else {
|
|
|
+ userLoginLog.setState(UserLoginLogState.PASSWORD_ERROR);
|
|
|
+ return Result.instance("用户名或密码错误,请重新输入");
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log.error("", e);
|
|
|
userLoginLog.setState(UserLoginLogState.LOGIN_EXCEPTION);
|