Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform
Commits
6228da47
Commit
6228da47
authored
May 22, 2019
by
hezhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改登录流程
parent
4bd29ffb
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
213 additions
and
15 deletions
+213
-15
AuthController.java
...thub/wxiaoqi/security/auth/controller/AuthController.java
+44
-6
IUserService.java
.../com/github/wxiaoqi/security/auth/feign/IUserService.java
+10
-1
AuthService.java
...com/github/wxiaoqi/security/auth/service/AuthService.java
+3
-0
AppAuthServiceImpl.java
...xiaoqi/security/auth/service/impl/AppAuthServiceImpl.java
+16
-0
AuthServiceImpl.java
...b/wxiaoqi/security/auth/service/impl/AuthServiceImpl.java
+16
-0
AppUserLoginBiz.java
...om/github/wxiaoqi/security/admin/biz/AppUserLoginBiz.java
+7
-0
AppUserRest.java
...va/com/github/wxiaoqi/security/admin/rpc/AppUserRest.java
+29
-0
AppPermissionService.java
...aoqi/security/admin/rpc/service/AppPermissionService.java
+88
-8
No files found.
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/controller/AuthController.java
View file @
6228da47
...
@@ -7,6 +7,7 @@ import com.github.wxiaoqi.security.common.constant.RequestTypeConstants;
...
@@ -7,6 +7,7 @@ import com.github.wxiaoqi.security.common.constant.RequestTypeConstants;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -89,7 +90,7 @@ public class AuthController {
...
@@ -89,7 +90,7 @@ public class AuthController {
@RequestParam
(
value
=
"nickname"
,
defaultValue
=
""
)
String
nickname
,
@RequestParam
(
value
=
"nickname"
,
defaultValue
=
""
)
String
nickname
,
@RequestParam
(
value
=
"headimgurl"
,
defaultValue
=
""
)
String
headimgurl
,
@RequestParam
(
value
=
"headimgurl"
,
defaultValue
=
""
)
String
headimgurl
,
@RequestParam
(
value
=
"openid"
,
defaultValue
=
""
)
String
openid
,
@RequestParam
(
value
=
"openid"
,
defaultValue
=
""
)
String
openid
,
@RequestParam
(
value
=
"
passwor
d"
,
defaultValue
=
""
)
String
unionid
,
@RequestParam
(
value
=
"
unioni
d"
,
defaultValue
=
""
)
String
unionid
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
,
@RequestParam
(
value
=
"isQQ"
,
defaultValue
=
"0"
)
Integer
isQQ
@RequestParam
(
value
=
"isQQ"
,
defaultValue
=
"0"
)
Integer
isQQ
)
throws
Exception
{
)
throws
Exception
{
...
@@ -97,11 +98,13 @@ public class AuthController {
...
@@ -97,11 +98,13 @@ public class AuthController {
JSONObject
data
=
appAuthService
.
wxregister
(
username
,
mobilecode
,
password
,
nickname
,
JSONObject
data
=
appAuthService
.
wxregister
(
username
,
mobilecode
,
password
,
nickname
,
headimgurl
,
openid
,
unionid
,
type
,
isQQ
);
headimgurl
,
openid
,
unionid
,
type
,
isQQ
);
if
(
data
!=
null
&&
data
.
getInteger
(
"status"
)==
ResultCode
.
SUCCESS_CODE
){
if
(
data
!=
null
&&
data
.
getInteger
(
"status"
)==
ResultCode
.
SUCCESS_CODE
){
JwtAuthenticationRequest
authenticationRequest
=
new
JwtAuthenticationRequest
();
JSONObject
result
=
data
.
getJSONObject
(
"data"
);
authenticationRequest
.
setUsername
(
username
);
if
(
result
==
null
){
authenticationRequest
.
setPassword
(
password
);
data
.
put
(
"status"
,
1001
);
String
token
=
appAuthService
.
login
(
authenticationRequest
);
}
else
{
data
.
put
(
"token"
,
token
);
String
token
=
appAuthService
.
getToken
(
username
,
result
.
getInteger
(
"userid"
));
data
.
put
(
"token"
,
token
);
}
}
}
return
data
;
return
data
;
}
}
...
@@ -116,4 +119,39 @@ public class AuthController {
...
@@ -116,4 +119,39 @@ public class AuthController {
return
appAuthService
.
wxlogin
(
openid
,
isQQ
);
return
appAuthService
.
wxlogin
(
openid
,
isQQ
);
}
}
@RequestMapping
(
value
=
"/login"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
login
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"1"
)
Integer
type
)
throws
Exception
{
log
.
info
(
username
+
"----require login..."
);
JSONObject
data
=
appAuthService
.
tlogin
(
username
,
password
,
mobilecode
,
type
);
if
(
data
!=
null
&&
data
.
getInteger
(
"status"
)==
ResultCode
.
SUCCESS_CODE
){
JSONObject
result
=
data
.
getJSONObject
(
"data"
);
if
(
result
==
null
){
data
.
put
(
"status"
,
1001
);
}
else
{
String
token
=
appAuthService
.
getToken
(
username
,
result
.
getInteger
(
"userid"
));
data
.
put
(
"token"
,
token
);
}
}
return
data
;
}
@RequestMapping
(
value
=
"/reset"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
reset
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
)
throws
Exception
{
log
.
info
(
username
+
"----require reset..."
);
JSONObject
data
=
appAuthService
.
reset
(
username
,
mobilecode
,
password
);
if
(
data
!=
null
&&
data
.
getInteger
(
"status"
)==
ResultCode
.
SUCCESS_CODE
){
JwtAuthenticationRequest
authenticationRequest
=
new
JwtAuthenticationRequest
();
authenticationRequest
.
setUsername
(
username
);
authenticationRequest
.
setPassword
(
password
);
String
token
=
appAuthService
.
login
(
authenticationRequest
);
data
.
put
(
"token"
,
token
);
}
return
data
;
}
}
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/feign/IUserService.java
View file @
6228da47
...
@@ -38,8 +38,17 @@ public interface IUserService {
...
@@ -38,8 +38,17 @@ public interface IUserService {
@RequestParam
(
value
=
"password"
)
String
password
,
@RequestParam
(
value
=
"nickname"
)
String
nickname
,
@RequestParam
(
value
=
"password"
)
String
password
,
@RequestParam
(
value
=
"nickname"
)
String
nickname
,
@RequestParam
(
value
=
"headimgurl"
)
String
headimgurl
,
@RequestParam
(
value
=
"openid"
)
String
openid
,
@RequestParam
(
value
=
"headimgurl"
)
String
headimgurl
,
@RequestParam
(
value
=
"openid"
)
String
openid
,
@RequestParam
(
value
=
"unionid"
)
String
unionid
,
@RequestParam
(
value
=
"type"
)
Integer
type
,
@RequestParam
(
value
=
"isQQ"
)
Integer
isQQ
);
@RequestParam
(
value
=
"unionid"
)
String
unionid
,
@RequestParam
(
value
=
"type"
)
Integer
type
,
@RequestParam
(
value
=
"isQQ"
)
Integer
isQQ
);
@RequestMapping
(
value
=
"/api/app/checkBindWechat"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/api/app/
user/
checkBindWechat"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
checkBindWechat
(
@RequestParam
(
value
=
"username"
)
String
username
);
public
JSONObject
checkBindWechat
(
@RequestParam
(
value
=
"username"
)
String
username
);
@RequestMapping
(
value
=
"/api/app/user/wxlogin"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/api/app/user/wxlogin"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
wxlogin
(
@RequestParam
(
value
=
"openid"
)
String
openid
,
@RequestParam
(
value
=
"isQQ"
)
Integer
isQQ
);
public
JSONObject
wxlogin
(
@RequestParam
(
value
=
"openid"
)
String
openid
,
@RequestParam
(
value
=
"isQQ"
)
Integer
isQQ
);
@RequestMapping
(
value
=
"/api/app/user/login"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
login
(
@RequestParam
(
value
=
"username"
)
String
username
,
@RequestParam
(
value
=
"password"
)
String
password
,
@RequestParam
(
value
=
"mobilecode"
)
String
mobilecode
,
@RequestParam
(
value
=
"type"
)
Integer
type
);
@RequestMapping
(
value
=
"/api/app/user/reset"
,
method
=
RequestMethod
.
POST
)
public
JSONObject
reset
(
@RequestParam
(
value
=
"username"
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
)
String
password
);
}
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/service/AuthService.java
View file @
6228da47
...
@@ -13,4 +13,7 @@ public interface AuthService {
...
@@ -13,4 +13,7 @@ public interface AuthService {
JSONObject
wxregister
(
String
username
,
String
mobilecode
,
String
password
,
String
nickname
,
String
headimgurl
,
String
openid
,
String
unionid
,
Integer
type
,
Integer
isQQ
)
throws
Exception
;
JSONObject
wxregister
(
String
username
,
String
mobilecode
,
String
password
,
String
nickname
,
String
headimgurl
,
String
openid
,
String
unionid
,
Integer
type
,
Integer
isQQ
)
throws
Exception
;
JSONObject
checkBindWechat
(
String
username
)
throws
Exception
;
JSONObject
checkBindWechat
(
String
username
)
throws
Exception
;
JSONObject
wxlogin
(
String
openid
,
Integer
isQQ
)
throws
Exception
;
JSONObject
wxlogin
(
String
openid
,
Integer
isQQ
)
throws
Exception
;
JSONObject
tlogin
(
String
username
,
String
password
,
String
mobilecode
,
Integer
type
)
throws
Exception
;
String
getToken
(
String
username
,
Integer
id
)
throws
Exception
;
JSONObject
reset
(
String
username
,
String
mobilecode
,
String
password
)
throws
Exception
;
}
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/service/impl/AppAuthServiceImpl.java
View file @
6228da47
...
@@ -70,4 +70,20 @@ public class AppAuthServiceImpl implements AuthService {
...
@@ -70,4 +70,20 @@ public class AppAuthServiceImpl implements AuthService {
return
userService
.
wxlogin
(
openid
,
isQQ
);
return
userService
.
wxlogin
(
openid
,
isQQ
);
}
}
@Override
public
JSONObject
tlogin
(
String
username
,
String
password
,
String
mobilecode
,
Integer
type
)
throws
Exception
{
return
userService
.
login
(
username
,
password
,
mobilecode
,
type
);
}
@Override
public
String
getToken
(
String
username
,
Integer
id
)
throws
Exception
{
return
jwtTokenUtil
.
generateToken
(
new
JWTInfo
(
username
,
id
+
""
,
null
,
RequestTypeConstants
.
APP
));
}
@Override
public
JSONObject
reset
(
String
username
,
String
mobilecode
,
String
password
)
throws
Exception
{
return
userService
.
reset
(
username
,
mobilecode
,
password
);
}
}
}
ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/service/impl/AuthServiceImpl.java
View file @
6228da47
...
@@ -7,6 +7,7 @@ import com.github.wxiaoqi.security.auth.feign.IUserService;
...
@@ -7,6 +7,7 @@ import com.github.wxiaoqi.security.auth.feign.IUserService;
import
com.github.wxiaoqi.security.auth.service.AuthService
;
import
com.github.wxiaoqi.security.auth.service.AuthService
;
import
com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest
;
import
com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest
;
import
com.github.wxiaoqi.security.auth.util.user.JwtTokenUtil
;
import
com.github.wxiaoqi.security.auth.util.user.JwtTokenUtil
;
import
com.github.wxiaoqi.security.common.constant.RequestTypeConstants
;
import
com.github.wxiaoqi.security.common.exception.auth.UserInvalidException
;
import
com.github.wxiaoqi.security.common.exception.auth.UserInvalidException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -67,4 +68,19 @@ public class AuthServiceImpl implements AuthService {
...
@@ -67,4 +68,19 @@ public class AuthServiceImpl implements AuthService {
public
JSONObject
wxlogin
(
String
openid
,
Integer
isQQ
)
throws
Exception
{
public
JSONObject
wxlogin
(
String
openid
,
Integer
isQQ
)
throws
Exception
{
return
userService
.
wxlogin
(
openid
,
isQQ
);
return
userService
.
wxlogin
(
openid
,
isQQ
);
}
}
@Override
public
JSONObject
tlogin
(
String
username
,
String
password
,
String
mobilecode
,
Integer
type
)
throws
Exception
{
return
userService
.
login
(
username
,
password
,
mobilecode
,
type
);
}
@Override
public
String
getToken
(
String
username
,
Integer
id
)
throws
Exception
{
return
jwtTokenUtil
.
generateToken
(
new
JWTInfo
(
username
,
id
+
""
,
null
,
RequestTypeConstants
.
APP
));
}
@Override
public
JSONObject
reset
(
String
username
,
String
mobilecode
,
String
password
)
throws
Exception
{
return
userService
.
reset
(
username
,
mobilecode
,
password
);
}
}
}
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/biz/AppUserLoginBiz.java
View file @
6228da47
...
@@ -47,6 +47,13 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
...
@@ -47,6 +47,13 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
super
.
updateSelectiveById
(
entity
);
super
.
updateSelectiveById
(
entity
);
}
}
@CacheClear
(
pre
=
"user{1.username}"
)
public
void
updatePasswordById
(
AppUserLogin
entity
)
{
String
password
=
new
BCryptPasswordEncoder
(
UserConstant
.
PW_ENCORDER_SALT
).
encode
(
entity
.
getPassword
());
entity
.
setPassword
(
password
);
super
.
updateSelectiveById
(
entity
);
}
/**
/**
* 根据用户名获取用户信息
* 根据用户名获取用户信息
...
...
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/rpc/AppUserRest.java
View file @
6228da47
...
@@ -130,5 +130,34 @@ public class AppUserRest {
...
@@ -130,5 +130,34 @@ public class AppUserRest {
return
appPermissionService
.
weCahtLogin
(
openid
,
isQQ
);
return
appPermissionService
.
weCahtLogin
(
openid
,
isQQ
);
}
}
/**
* 登录
* @param username
* @param mobilecode
* @param password
* @param type 1-账号密码;2-验证码
* @return
*/
@RequestMapping
(
value
=
"/user/login"
,
method
=
RequestMethod
.
POST
)
public
@ResponseBody
JSONObject
login
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"1"
)
Integer
type
){
return
appPermissionService
.
login
(
username
,
password
,
mobilecode
,
type
);
}
@RequestMapping
(
value
=
"/user/reset"
,
method
=
RequestMethod
.
POST
)
public
@ResponseBody
JSONObject
login
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"mobilecode"
,
defaultValue
=
""
)
String
mobilecode
,
@RequestParam
(
value
=
"password"
,
defaultValue
=
""
)
String
password
){
return
appPermissionService
.
reset
(
username
,
mobilecode
,
password
);
}
}
}
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/rpc/service/AppPermissionService.java
View file @
6228da47
...
@@ -121,8 +121,8 @@ public class AppPermissionService {
...
@@ -121,8 +121,8 @@ public class AppPermissionService {
return JsonResultUtil.createFailedResult(ResultCode.FAILED_CODE, "手机号未注册,请确认手机号无误");
return JsonResultUtil.createFailedResult(ResultCode.FAILED_CODE, "手机号未注册,请确认手机号无误");
}*/
else
if
(
type
==
4
)
{
}*/
else
if
(
type
==
4
)
{
AppUserLogin
rsUserLogin
=
appUserLoginBiz
.
checkeUserLogin
(
phone
);
AppUserLogin
rsUserLogin
=
appUserLoginBiz
.
checkeUserLogin
(
phone
);
if
(
rsUserLogin
!
=
null
)
if
(
rsUserLogin
=
=
null
)
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"手机号
已
注册"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"手机号
未
注册"
);
}
}
// String sms = PassportUtil.SendSMS(phone, SystemConfig.SENDSMS_TITLE);
// String sms = PassportUtil.SendSMS(phone, SystemConfig.SENDSMS_TITLE);
String
mobilecode
=
"123456"
;
String
mobilecode
=
"123456"
;
...
@@ -172,11 +172,11 @@ public class AppPermissionService {
...
@@ -172,11 +172,11 @@ public class AppPermissionService {
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
}
String
redisLockKey
=
RedisKey
.
CONSTANT_CODE_PREFIX
+
username
+
mobilecode
;
String
redisLockKey
=
RedisKey
.
CONSTANT_CODE_PREFIX
+
username
+
mobilecode
;
String
mobilecodeRedis
=
String
.
valueOf
(
userRedisTemplate
.
opsForValue
().
get
(
redisLockKey
)
);
String
mobilecodeRedis
=
userRedisTemplate
.
opsForValue
().
get
(
redisLockKey
)==
null
?
""
:
userRedisTemplate
.
opsForValue
().
get
(
redisLockKey
).
toString
(
);
log
.
error
(
"注册接口,获取redis中的验证码:"
+
mobilecodeRedis
);
log
.
error
(
"注册接口,获取redis中的验证码:"
+
mobilecodeRedis
);
// 获取到缓存的验证码后要先清空缓存对应键的值
// 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate
.
delete
(
redisLockKey
);
userRedisTemplate
.
delete
(
redisLockKey
);
if
(
mobilecodeRedis
==
null
)
{
if
(
StringUtils
.
isBlank
(
mobilecodeRedis
)
)
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"验证码错误"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"验证码错误"
);
}
}
// 是否已存在
// 是否已存在
...
@@ -241,6 +241,17 @@ public class AppPermissionService {
...
@@ -241,6 +241,17 @@ public class AppPermissionService {
JSONObject
data
=
new
JSONObject
();
JSONObject
data
=
new
JSONObject
();
AppUserLogin
userLoign
=
appUserLoginBiz
.
selectById
(
userid
);
AppUserLogin
userLoign
=
appUserLoginBiz
.
selectById
(
userid
);
if
(
userLoign
!=
null
)
{
if
(
userLoign
!=
null
)
{
data
.
put
(
"nickname"
,
nickname
);
data
.
put
(
"headerurl"
,
headimgurl
);
AppUserDetail
appUserDetail
=
appUserDetailBiz
.
getUserByUserid
(
userid
);
if
(
appUserDetail
!=
null
){
if
(
StringUtils
.
isNotBlank
(
appUserDetail
.
getNickname
())){
data
.
put
(
"nickname"
,
appUserDetail
.
getNickname
());
}
if
(
StringUtils
.
isNotBlank
(
appUserDetail
.
getHeadimgurl
())){
data
.
put
(
"headerurl"
,
appUserDetail
.
getHeadimgurl
());
}
}
// 缓存操作
// 缓存操作
String
token
=
""
;
String
token
=
""
;
String
imtoken_
=
""
;
String
imtoken_
=
""
;
...
@@ -250,8 +261,7 @@ public class AppPermissionService {
...
@@ -250,8 +261,7 @@ public class AppPermissionService {
// data.put("token", token);
// data.put("token", token);
data
.
put
(
"username"
,
username
);
data
.
put
(
"username"
,
username
);
data
.
put
(
"userid"
,
userid
);
data
.
put
(
"userid"
,
userid
);
data
.
put
(
"nickname"
,
nickname
);
data
.
put
(
"headerurl"
,
headimgurl
);
}
}
return
data
;
return
data
;
}
}
...
@@ -331,7 +341,7 @@ public class AppPermissionService {
...
@@ -331,7 +341,7 @@ public class AppPermissionService {
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
}
}
}
else
if
(
type
==
2
)
{
// 新增
}
else
if
(
type
==
2
)
{
// 新增
JSONObject
register
=
register
(
username
,
password
,
nickname
,
headimgurl
,
mobilecode
,
JSONObject
register
=
register
(
username
,
password
,
headimgurl
,
nickname
,
mobilecode
,
openId
,
unionid
,
isQQ
);
openId
,
unionid
,
isQQ
);
if
(
register
.
getInteger
(
"status"
)
!=
ResultCode
.
SUCCESS_CODE
)
{
if
(
register
.
getInteger
(
"status"
)
!=
ResultCode
.
SUCCESS_CODE
)
{
if
(
register
.
getInteger
(
"status"
)
==
ResultCode
.
EXIST_CODE
)
{
if
(
register
.
getInteger
(
"status"
)
==
ResultCode
.
EXIST_CODE
)
{
...
@@ -391,7 +401,7 @@ public class AppPermissionService {
...
@@ -391,7 +401,7 @@ public class AppPermissionService {
}
}
AppUserLogin
userLogin
=
appUserLoginBiz
.
getUserByOpenid
(
openId
,
isQQ
);
AppUserLogin
userLogin
=
appUserLoginBiz
.
getUserByOpenid
(
openId
,
isQQ
);
if
(
userLogin
==
null
){
if
(
userLogin
==
null
){
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
WXNOTEXIST_CODE
,
"该微信号尚未绑定手机号"
,
openId
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
WXNOTEXIST_CODE
,
"该微信号尚未绑定手机号"
);
}
}
if
(
userLogin
.
getStatus
()==
1
){
if
(
userLogin
.
getStatus
()==
1
){
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"用户已被禁用"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"用户已被禁用"
);
...
@@ -411,4 +421,74 @@ public class AppPermissionService {
...
@@ -411,4 +421,74 @@ public class AppPermissionService {
return
JsonResultUtil
.
createDefaultFail
();
return
JsonResultUtil
.
createDefaultFail
();
}
}
public
JSONObject
login
(
String
username
,
String
password
,
String
mobilecode
,
int
type
)
{
if
(
StringUtils
.
isBlank
(
username
)
||
((
StringUtils
.
isBlank
(
password
)&&
type
==
1
)||
(
StringUtils
.
isBlank
(
mobilecode
)&&
type
==
2
)))
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"请求参数为空"
);
}
try
{
AppUserLogin
user
=
appUserLoginBiz
.
checkeUserLogin
(
username
);
if
(
type
==
1
){
if
(
user
==
null
||!
encoder
.
matches
(
password
,
user
.
getPassword
()))
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"用户名或密码错误"
);
}
else
{
String
redisLockKey
=
RedisKey
.
CONSTANT_CODE_PREFIX
+
username
+
mobilecode
;
String
mobilecodeRedis
=
userRedisTemplate
.
opsForValue
().
get
(
redisLockKey
)==
null
?
""
:
userRedisTemplate
.
opsForValue
().
get
(
redisLockKey
).
toString
();
log
.
error
(
"验证码登录接口,获取redis中的验证码:"
+
mobilecodeRedis
);
// 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate
.
delete
(
redisLockKey
);
if
(
StringUtils
.
isBlank
(
mobilecodeRedis
))
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"验证码错误"
);
if
(
user
==
null
)
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"用户不存在"
);
}
// 判断是否禁用
if
(
user
.
getStatus
()
==
1
)
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"用户已被禁用"
);
}
Integer
userid
=
user
.
getId
();
String
nickname
=
SystemConfig
.
USER_NIKENAME_DEFAULT
+(
int
)((
Math
.
random
()*
9
+
1
)*
100000
);
JSONObject
data
=
autoLogin
(
userid
,
user
.
getUsername
(),
SystemConfig
.
USER_HEADER_URL_DEFAULT
,
nickname
);
if
(
data
!=
null
)
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
}
return
JsonResultUtil
.
createDefaultFail
();
}
catch
(
Exception
e
)
{
log
.
error
(
"userlogin->error:{}"
,
e
.
getMessage
(),
e
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
}
}
@Transactional
public
JSONObject
reset
(
String
username
,
String
mobilecode
,
String
password
)
{
if
(
StringUtils
.
isBlank
(
username
)
||
StringUtils
.
isBlank
(
mobilecode
)||
StringUtils
.
isBlank
(
password
))
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"请求参数为空"
);
}
try
{
String
redisLockKey
=
RedisKey
.
CONSTANT_CODE_PREFIX
+
username
+
mobilecode
;
String
mobilecodeRedis
=
userRedisTemplate
.
opsForValue
().
get
(
redisLockKey
)==
null
?
""
:
userRedisTemplate
.
opsForValue
().
get
(
redisLockKey
).
toString
();
log
.
error
(
"验证码登录接口,获取redis中的验证码:"
+
mobilecodeRedis
);
// 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate
.
delete
(
redisLockKey
);
if
(
StringUtils
.
isBlank
(
mobilecodeRedis
)){
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"验证码错误"
);
}
AppUserLogin
user
=
appUserLoginBiz
.
checkeUserLogin
(
username
);
if
(
user
==
null
){
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NOTEXIST_CODE
,
"用户不存在"
);
}
user
.
setPassword
(
password
);
appUserLoginBiz
.
updatePasswordById
(
user
);
Integer
userid
=
user
.
getId
();
String
nickname
=
SystemConfig
.
USER_NIKENAME_DEFAULT
+(
int
)((
Math
.
random
()*
9
+
1
)*
100000
);
JSONObject
data
=
autoLogin
(
userid
,
user
.
getUsername
(),
SystemConfig
.
USER_HEADER_URL_DEFAULT
,
nickname
);
if
(
data
!=
null
)
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
data
);
}
return
JsonResultUtil
.
createDefaultFail
();
}
catch
(
Exception
e
)
{
log
.
error
(
"userlogin->error:{}"
,
e
.
getMessage
(),
e
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment