Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
77e20b3b
Commit
77e20b3b
authored
Dec 29, 2016
by
zhouqian
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitabc.xyqb.com/head_group/xyqb-user2
parents
47fcd152
eb925cd3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
1 deletion
+104
-1
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+104
-1
No files found.
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
77e20b3b
...
@@ -8,6 +8,7 @@ import cn.quantgroup.xyqb.model.AuthBean;
...
@@ -8,6 +8,7 @@ import cn.quantgroup.xyqb.model.AuthBean;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.UserModel
;
import
cn.quantgroup.xyqb.model.UserModel
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
import
cn.quantgroup.xyqb.model.session.SessionStruct
;
import
cn.quantgroup.xyqb.model.session.SessionValue
;
import
cn.quantgroup.xyqb.repository.IUserDetailRepository
;
import
cn.quantgroup.xyqb.repository.IUserDetailRepository
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.sms.ISmsService
;
import
cn.quantgroup.xyqb.service.sms.ISmsService
;
...
@@ -15,11 +16,13 @@ import cn.quantgroup.xyqb.service.user.IUserService;
...
@@ -15,11 +16,13 @@ import cn.quantgroup.xyqb.service.user.IUserService;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
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.data.annotation.CreatedBy
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -29,7 +32,13 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -29,7 +32,13 @@ import org.springframework.web.bind.annotation.RestController;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.security.Principal
;
import
java.security.Principal
;
import
java.sql.Timestamp
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.Random
;
import
java.util.UUID
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
/**
* Created by FrankChow on 15/7/5.
* Created by FrankChow on 15/7/5.
...
@@ -69,6 +78,8 @@ public class UserController implements IBaseController {
...
@@ -69,6 +78,8 @@ public class UserController implements IBaseController {
@Autowired
@Autowired
private
IUserDetailRepository
userDetailRepository
;
private
IUserDetailRepository
userDetailRepository
;
public
static
final
String
SMS_VERIFY_PREFIX
=
"sms:verify:"
;
private
static
final
char
[]
PWD_BASE
=
{
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
'k'
,
private
static
final
char
[]
PWD_BASE
=
{
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
'k'
,
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'l'
,
'm'
,
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
};
'x'
,
'y'
,
'z'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
};
...
@@ -145,11 +156,103 @@ public class UserController implements IBaseController {
...
@@ -145,11 +156,103 @@ public class UserController implements IBaseController {
*
*
* @return
* @return
*/
*/
@RequestMapping
(
"/login/fast"
)
/*
@RequestMapping("/login/fast")
public JsonResult loginFast(Principal user) {
public JsonResult loginFast(Principal user) {
AuthBean bean = new AuthBean(getRequest().getSession().getId(), user);
AuthBean bean = new AuthBean(getRequest().getSession().getId(), user);
LOGGER.info("用户快速登录成功, loginFrom:{}, phoneNo:{},appChannel:{}", getCreatedFrom(), user.getName(), getAppChannel());
LOGGER.info("用户快速登录成功, loginFrom:{}, phoneNo:{},appChannel:{}", getCreatedFrom(), user.getName(), getAppChannel());
return new JsonResult(bean);
return new JsonResult(bean);
}*/
@RequestMapping
(
"/login/fast"
)
public
JsonResult
loginFast
(
HttpServletRequest
request
){
String
verificationHeader
=
"Verification "
;
String
credential
=
request
.
getHeader
(
"authorization"
);
if
(
StringUtils
.
isBlank
(
credential
)){
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
if
(!
credential
.
startsWith
(
verificationHeader
)){
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
credential
=
credential
.
substring
(
verificationHeader
.
length
(),
credential
.
length
());
byte
[]
buf
=
Base64
.
decodeBase64
(
credential
);
try
{
credential
=
new
String
(
buf
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
){
LOGGER
.
error
(
"不支持的编码."
);
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
String
[]
credentialArr
=
credential
.
split
(
":"
);
if
(
credentialArr
.
length
!=
2
){
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
String
phoneNo
=
credentialArr
[
0
];
String
verificationCode
=
credentialArr
[
1
];
if
(!
matchPhoneNo
(
phoneNo
)){
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
if
(!
validateVerificationCode
(
phoneNo
,
verificationCode
)){
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
User
user
=
userService
.
findByPhone
(
phoneNo
);
if
(
user
==
null
){
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
String
sessionId
=
sessionService
.
findSessionIdByUserId
(
user
.
getId
());
if
(
StringUtils
.
isBlank
(
sessionId
)){
return
JsonResult
.
buildErrorStateResult
(
"登录失败"
,
null
);
}
SessionStruct
sessionStruct
=
null
;
if
(
sessionId
.
length
()
==
36
){
String
value
=
sessionService
.
findSessionValueBySessionId
(
sessionId
);
if
(
StringUtils
.
isBlank
(
value
)){
sessionStruct
=
sessionService
.
newSession
(
user
);
SessionValue
sessionValue
=
new
SessionValue
();
sessionValue
.
setUser
(
user
);
sessionValue
.
setLastAccessTime
(
new
Timestamp
(
System
.
currentTimeMillis
()));
sessionValue
.
setCreatedAt
(
new
Timestamp
(
System
.
currentTimeMillis
()));
Map
<
String
,
String
>
values
=
new
HashMap
();
sessionValue
.
setValues
(
values
);
sessionService
.
persistSession
(
sessionStruct
.
getSid
(),
sessionValue
);
}
sessionStruct
.
setSid
(
sessionId
);
}
else
{
sessionStruct
=
sessionService
.
newSession
(
user
);
sessionService
.
persistSession
(
sessionStruct
.
getSid
(),
sessionService
.
newSession
(
user
).
getValues
());
}
AuthBean
authBean
=
new
AuthBean
();
authBean
.
setPhoneNo
(
user
.
getPhoneNo
());
authBean
.
setToken
(
sessionStruct
.
getSid
());
return
new
JsonResult
(
authBean
);
}
private
boolean
validateVerificationCode
(
String
phoneNo
,
String
verificationCode
){
String
key
=
SMS_VERIFY_PREFIX
+
phoneNo
;
String
randomCode
=
stringRedisTemplate
.
opsForValue
().
get
(
key
);
if
(
StringUtils
.
isBlank
(
randomCode
)){
return
false
;
}
String
[]
arr
=
randomCode
.
split
(
":"
);
if
(
arr
.
length
!=
2
){
return
false
;
}
String
uniqueId
=
arr
[
0
];
String
code
=
arr
[
1
];
if
(
code
==
verificationCode
){
stringRedisTemplate
.
delete
(
key
);
//todo 发送mq消息,后续补
return
true
;
}
return
false
;
}
private
boolean
matchPhoneNo
(
String
phoneNo
){
String
patternString
=
"1\\d{10}"
;
Pattern
pattern
=
Pattern
.
compile
(
patternString
);
Matcher
matcher
=
pattern
.
matcher
(
phoneNo
);
if
(
matcher
.
matches
()){
return
true
;
}
return
false
;
}
}
/**
/**
...
...
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