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
ab172d63
Commit
ab172d63
authored
Jan 16, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/20180108' into feature/junit_test
parents
485da10e
5147293c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
46 deletions
+16
-46
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+8
-23
ISmsService.java
...main/java/cn/quantgroup/xyqb/service/sms/ISmsService.java
+7
-4
SmsServiceImpl.java
...a/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
+1
-19
No files found.
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
ab172d63
...
@@ -52,9 +52,7 @@ import java.util.Objects;
...
@@ -52,9 +52,7 @@ import java.util.Objects;
@RequestMapping
(
"/user"
)
@RequestMapping
(
"/user"
)
public
class
UserController
implements
IBaseController
{
public
class
UserController
implements
IBaseController
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
private
final
String
pwdSalt
=
"_lkb"
;
@Autowired
@Autowired
private
IUserService
userService
;
private
IUserService
userService
;
...
@@ -188,7 +186,7 @@ public class UserController implements IBaseController {
...
@@ -188,7 +186,7 @@ public class UserController implements IBaseController {
}
}
String
verificationCode
=
successResult
.
getMsg
();
String
verificationCode
=
successResult
.
getMsg
();
// 执行短信验证码检查
// 执行短信验证码检查
smsValidForFastLogin
(
phoneNo
,
verificationCode
);
verifyPhoneAndCode
(
phoneNo
,
verificationCode
);
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
User
user
=
userService
.
findByPhoneWithCache
(
phoneNo
);
if
(
user
!=
null
&&
!
user
.
getEnable
())
{
if
(
user
!=
null
&&
!
user
.
getEnable
())
{
LOGGER
.
error
(
"用户不存在,或者已经注销,phoneNo:{}"
,
phoneNo
);
LOGGER
.
error
(
"用户不存在,或者已经注销,phoneNo:{}"
,
phoneNo
);
...
@@ -274,7 +272,7 @@ public class UserController implements IBaseController {
...
@@ -274,7 +272,7 @@ public class UserController implements IBaseController {
if
(
null
==
registerFrom
)
{
if
(
null
==
registerFrom
)
{
registerFrom
=
1L
;
registerFrom
=
1L
;
}
}
smsValidForRegister
(
phoneNo
,
verificationCode
);
verifyPhoneAndCode
(
phoneNo
,
verificationCode
);
if
(
userService
.
exist
(
phoneNo
))
{
if
(
userService
.
exist
(
phoneNo
))
{
LOGGER
.
info
(
"用户注册失败,该手机号已经被注册:register -> registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
LOGGER
.
info
(
"用户注册失败,该手机号已经被注册:register -> registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
return
JsonResult
.
buildErrorStateResult
(
"该手机号已经被注册"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"该手机号已经被注册"
,
null
);
...
@@ -338,7 +336,7 @@ public class UserController implements IBaseController {
...
@@ -338,7 +336,7 @@ public class UserController implements IBaseController {
if
(
password
.
length
()
<
6
||
password
.
length
()
>
12
)
{
if
(
password
.
length
()
<
6
||
password
.
length
()
>
12
)
{
return
JsonResult
.
buildErrorStateResult
(
"密码应为6-12位"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"密码应为6-12位"
,
null
);
}
}
smsValidForRegister
(
phoneNo
,
verificationCode
);
verifyPhoneAndCode
(
phoneNo
,
verificationCode
);
if
(!
userService
.
exist
(
phoneNo
))
{
if
(!
userService
.
exist
(
phoneNo
))
{
LOGGER
.
info
(
"修改密码失败,该手机号尚未注册, registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
LOGGER
.
info
(
"修改密码失败,该手机号尚未注册, registerFrom:{}, phoneNo:{}"
,
registerFrom
,
phoneNo
);
return
JsonResult
.
buildErrorStateResult
(
"该手机号尚未注册"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"该手机号尚未注册"
,
null
);
...
@@ -441,7 +439,7 @@ public class UserController implements IBaseController {
...
@@ -441,7 +439,7 @@ public class UserController implements IBaseController {
}
}
private
boolean
validatePassword
(
String
paramPass
,
String
targetPassword
)
{
private
boolean
validatePassword
(
String
paramPass
,
String
targetPassword
)
{
return
StringUtils
.
defaultString
(
targetPassword
,
""
).
equals
(
PasswordUtil
.
MD5
(
paramPass
.
toLowerCase
()
+
pwdSalt
));
return
StringUtils
.
defaultString
(
targetPassword
,
""
).
equals
(
PasswordUtil
.
MD5
(
paramPass
.
toLowerCase
()
+
Constants
.
PASSWORD_SALT
));
}
}
private
JsonResult
loginWithUserId
(
Long
channelId
,
String
appChannel
,
Long
createdFrom
,
String
userId
,
Merchant
merchant
,
String
dimension
)
{
private
JsonResult
loginWithUserId
(
Long
channelId
,
String
appChannel
,
Long
createdFrom
,
String
userId
,
Merchant
merchant
,
String
dimension
)
{
...
@@ -488,27 +486,14 @@ public class UserController implements IBaseController {
...
@@ -488,27 +486,14 @@ public class UserController implements IBaseController {
}
}
/**
/**
* 注册时校验短信验证码
* 校验短信验证码
* @param phoneNo
* @param verificationCode
*/
private
void
smsValidForRegister
(
String
phoneNo
,
String
verificationCode
)
{
if
(!
smsService
.
validRegisterOrResetPasswdVerificationCode
(
phoneNo
,
verificationCode
))
{
smsReSendOrNot
(
phoneNo
);
LOGGER
.
info
(
"用户快速注册,验证码校验失败,phoneNo:{} , verificationCode:{}"
,
phoneNo
,
verificationCode
);
throw
new
VerificationCodeErrorException
(
"短信验证码错误"
);
}
}
/**
* 登录时校验短信验证码
* @param phoneNo
* @param phoneNo
* @param verificationCode
* @param verificationCode
*/
*/
private
void
smsValidForFastLogin
(
String
phoneNo
,
String
verificationCode
)
{
private
void
verifyPhoneAndCode
(
String
phoneNo
,
String
verificationCode
)
{
if
(!
smsService
.
v
alidateFastLoginVerification
Code
(
phoneNo
,
verificationCode
))
{
if
(!
smsService
.
v
erifyPhoneAnd
Code
(
phoneNo
,
verificationCode
))
{
smsReSendOrNot
(
phoneNo
);
smsReSendOrNot
(
phoneNo
);
LOGGER
.
info
(
"
用户快速登录,
验证码校验失败,phoneNo:{} , verificationCode:{}"
,
phoneNo
,
verificationCode
);
LOGGER
.
info
(
"验证码校验失败,phoneNo:{} , verificationCode:{}"
,
phoneNo
,
verificationCode
);
throw
new
VerificationCodeErrorException
(
"短信验证码错误"
);
throw
new
VerificationCodeErrorException
(
"短信验证码错误"
);
}
}
}
}
...
...
src/main/java/cn/quantgroup/xyqb/service/sms/ISmsService.java
View file @
ab172d63
package
cn
.
quantgroup
.
xyqb
.
service
.
sms
;
package
cn
.
quantgroup
.
xyqb
.
service
.
sms
;
import
cn.quantgroup.sms.SmsSender
;
import
cn.quantgroup.sms.SmsSender
;
import
cn.quantgroup.xyqb.model.sms.SmsResult
;
/**
/**
* 短信发送服务
* 短信发送服务
...
@@ -17,8 +16,12 @@ public interface ISmsService {
...
@@ -17,8 +16,12 @@ public interface ISmsService {
void
sendAfterRegister
(
String
phoneNo
,
String
contentId
);
void
sendAfterRegister
(
String
phoneNo
,
String
contentId
);
boolean
validRegisterOrResetPasswdVerificationCode
(
String
phoneNo
,
String
smsVerificationCode
);
/**
* 验证手机号和验证码是否匹配
boolean
validateFastLoginVerificationCode
(
String
phoneNo
,
String
verificationCode
);
* @param phoneNo 手机号
* @param verificationCode 验证码(短信/语音)
* @return
*/
boolean
verifyPhoneAndCode
(
String
phoneNo
,
String
verificationCode
);
}
}
src/main/java/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
View file @
ab172d63
...
@@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Value;
...
@@ -17,7 +17,6 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
/**
/**
* @author mengfan.feng
* @author mengfan.feng
...
@@ -82,24 +81,7 @@ public class SmsServiceImpl implements ISmsService {
...
@@ -82,24 +81,7 @@ public class SmsServiceImpl implements ISmsService {
* 检查验证码是否正确
* 检查验证码是否正确
*/
*/
@Override
@Override
public
boolean
validRegisterOrResetPasswdVerificationCode
(
String
phoneNo
,
public
boolean
verifyPhoneAndCode
(
String
phoneNo
,
String
verificationCode
)
{
String
smsVerificationCode
)
{
//if (StringUtils.isEmpty(smsVerificationCode) || smsVerificationCode.length() != SMS_VERIFICATION_MAXLEN) {
// return false;
//}
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
String
randomCode
=
stringRedisTemplate
.
opsForValue
().
get
(
key
);
if
(
StringUtils
.
isEmpty
(
randomCode
))
{
return
false
;
}
String
[]
arr
=
randomCode
.
split
(
":"
);
String
uniqueId
=
arr
[
0
];
String
code
=
arr
[
1
];
return
confirmSms
(
smsVerificationCode
,
uniqueId
,
code
);
}
@Override
public
boolean
validateFastLoginVerificationCode
(
String
phoneNo
,
String
verificationCode
)
{
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
String
randomCode
=
stringRedisTemplate
.
opsForValue
().
get
(
key
);
String
randomCode
=
stringRedisTemplate
.
opsForValue
().
get
(
key
);
if
(
StringUtils
.
isBlank
(
randomCode
))
{
if
(
StringUtils
.
isBlank
(
randomCode
))
{
...
...
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