Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
c11a31f4
Commit
c11a31f4
authored
Feb 03, 2020
by
张晋雄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
短信验证登陆
parent
ff564007
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
90 additions
and
5 deletions
+90
-5
src/main/java/cn/meteor/beyondclouds/modules/user/api/AuthenticationApi.java
+16
-0
src/main/java/cn/meteor/beyondclouds/modules/user/form/SmsAuthFrom.java
+25
-0
src/main/java/cn/meteor/beyondclouds/modules/user/service/IAuthenticationService.java
+9
-0
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/AuthenticationServiceImpl.java
+36
-1
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/UserServiceImpl.java
+2
-2
src/main/resources/application-prod.yml
+1
-1
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/cn/meteor/beyondclouds/modules/user/api/AuthenticationApi.java
View file @
c11a31f4
...
...
@@ -6,7 +6,9 @@ import cn.meteor.beyondclouds.core.api.Response;
import
cn.meteor.beyondclouds.core.bean.Subject
;
import
cn.meteor.beyondclouds.modules.user.bean.AuthenticationResult
;
import
cn.meteor.beyondclouds.modules.user.exception.AuthenticationServiceException
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
cn.meteor.beyondclouds.modules.user.form.LocalAuthFrom
;
import
cn.meteor.beyondclouds.modules.user.form.SmsAuthFrom
;
import
cn.meteor.beyondclouds.modules.user.service.IAuthenticationService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -46,6 +48,20 @@ public class AuthenticationApi {
}
@Anonymous
@ApiOperation
(
value
=
"短信验证登陆"
)
@PostMapping
(
"/sms"
)
public
Response
<
AuthenticationResult
>
smsAuth
(
@RequestBody
@Valid
@ApiParam
(
"短信认证表单"
)
SmsAuthFrom
smsAuthFrom
)
throws
UserServiceException
{
AuthenticationResult
authenticationResult
=
null
;
try
{
authenticationResult
=
authenticationService
.
smsAuthentication
(
smsAuthFrom
.
getMobile
(),
smsAuthFrom
.
getVerifyCode
());
return
Response
.
success
(
authenticationResult
);
}
catch
(
AuthenticationServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
@Anonymous
@ApiOperation
(
value
=
"QQ认证"
)
@GetMapping
(
"/qq"
)
public
Response
<
AuthenticationResult
>
qqAuth
(
@RequestParam
(
"code"
)
String
code
)
{
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/form/SmsAuthFrom.java
0 → 100644
View file @
c11a31f4
package
cn
.
meteor
.
beyondclouds
.
modules
.
user
.
form
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @program: beyond-clouds
* @description: 短信认证表单
* @author: Mr.Zhang
* @create: 2020-02-03 09:49
**/
@ApiModel
(
"短信验证表单"
)
@Data
public
class
SmsAuthFrom
{
@ApiModelProperty
(
"手机号"
)
private
String
mobile
;
@ApiModelProperty
(
"验证码"
)
private
String
verifyCode
;
}
src/main/java/cn/meteor/beyondclouds/modules/user/service/IAuthenticationService.java
View file @
c11a31f4
...
...
@@ -2,6 +2,7 @@ package cn.meteor.beyondclouds.modules.user.service;
import
cn.meteor.beyondclouds.modules.user.bean.AuthenticationResult
;
import
cn.meteor.beyondclouds.modules.user.exception.AuthenticationServiceException
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
/**
* 认证服务
...
...
@@ -23,4 +24,12 @@ public interface IAuthenticationService {
* @return
*/
AuthenticationResult
qqAuthentication
(
String
code
)
throws
AuthenticationServiceException
;
/**
* 短信验证登陆
* @param mobile
* @param verifyCode
* @return
*/
AuthenticationResult
smsAuthentication
(
String
mobile
,
String
verifyCode
)
throws
UserServiceException
,
AuthenticationServiceException
;
}
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/AuthenticationServiceImpl.java
View file @
c11a31f4
...
...
@@ -3,9 +3,13 @@ package cn.meteor.beyondclouds.modules.user.service.impl;
import
cn.meteor.beyondclouds.common.bean.QQAuthResult
;
import
cn.meteor.beyondclouds.common.exception.QQAuthenticationException
;
import
cn.meteor.beyondclouds.common.helper.IQQAuthenticationHelper
;
import
cn.meteor.beyondclouds.common.helper.IRedisHelper
;
import
cn.meteor.beyondclouds.core.redis.RedisKey
;
import
cn.meteor.beyondclouds.modules.user.entity.UserAuthApp
;
import
cn.meteor.beyondclouds.modules.user.entity.UserAuthLocal
;
import
cn.meteor.beyondclouds.modules.user.enums.ThirdPartyAppType
;
import
cn.meteor.beyondclouds.modules.user.enums.UserErrorCode
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
cn.meteor.beyondclouds.modules.user.service.IUserAuthAppService
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
import
cn.meteor.beyondclouds.util.JsonUtils
;
...
...
@@ -19,6 +23,7 @@ import cn.meteor.beyondclouds.util.Md5Utils;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.HashMap
;
...
...
@@ -38,12 +43,19 @@ public class AuthenticationServiceImpl implements IAuthenticationService {
private
IUserService
userService
;
private
IRedisHelper
redisHelper
;
@Autowired
public
AuthenticationServiceImpl
(
IUserAuthLocalService
userAuthLocalService
,
IQQAuthenticationHelper
iqqAuthenticationHelper
,
IUserAuthAppService
userAuthAppService
,
IUserService
userService
)
{
public
AuthenticationServiceImpl
(
IUserAuthLocalService
userAuthLocalService
,
IQQAuthenticationHelper
iqqAuthenticationHelper
,
IUserAuthAppService
userAuthAppService
,
IUserService
userService
,
IRedisHelper
redisHelper
)
{
this
.
userAuthLocalService
=
userAuthLocalService
;
this
.
iqqAuthenticationHelper
=
iqqAuthenticationHelper
;
this
.
userAuthAppService
=
userAuthAppService
;
this
.
userService
=
userService
;
this
.
redisHelper
=
redisHelper
;
}
@Override
...
...
@@ -93,6 +105,29 @@ public class AuthenticationServiceImpl implements IAuthenticationService {
}
}
@Override
public
AuthenticationResult
smsAuthentication
(
String
mobile
,
String
verifyCode
)
throws
UserServiceException
,
AuthenticationServiceException
{
//1.检查验证码是否正确
String
realVerifyCode
=
redisHelper
.
get
(
RedisKey
.
VERIFY_CODE_KEY
(
mobile
));
if
(
StringUtils
.
isEmpty
(
realVerifyCode
)
||
!
realVerifyCode
.
equals
(
verifyCode
))
{
throw
new
UserServiceException
(
UserErrorCode
.
REG_VERIFY_CODE_ERROR
);
}
// 删除验证码
redisHelper
.
del
(
RedisKey
.
VERIFY_CODE_KEY
(
mobile
));
//2. 查找用户是否存在
UserAuthLocal
userAuthLocal
=
userAuthLocalService
.
getByMobile
(
mobile
);
if
(
null
==
userAuthLocal
)
{
throw
new
AuthenticationServiceException
(
AuthenticationErrorCode
.
USER_NOT_FOUND
);
}
// 根据userId生成token并返回
return
makeAuthenticationResult
(
userAuthLocal
.
getUserId
());
}
/**
* 制造认证结果
* @param userId
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/UserServiceImpl.java
View file @
c11a31f4
...
...
@@ -41,10 +41,10 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
}
@Override
public
void
register
(
String
mobile
,
String
password
,
String
verifyC
O
de
)
throws
UserServiceException
{
public
void
register
(
String
mobile
,
String
password
,
String
verifyC
o
de
)
throws
UserServiceException
{
//1.检查验证码是否正确
String
realVerifyCode
=
redisHelper
.
get
(
RedisKey
.
VERIFY_CODE_KEY
(
mobile
));
if
(
StringUtils
.
isEmpty
(
realVerifyCode
)
||
!
realVerifyCode
.
equals
(
verifyC
O
de
))
{
if
(
StringUtils
.
isEmpty
(
realVerifyCode
)
||
!
realVerifyCode
.
equals
(
verifyC
o
de
))
{
throw
new
UserServiceException
(
UserErrorCode
.
REG_VERIFY_CODE_ERROR
);
}
...
...
src/main/resources/application-prod.yml
View file @
c11a31f4
...
...
@@ -3,7 +3,7 @@ spring:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username
:
root
password
:
100Centa30821%mysql
password
:
2018006709
swagger
:
enable
:
true
...
...
src/main/resources/application.yml
View file @
c11a31f4
...
...
@@ -3,7 +3,7 @@ spring:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username
:
root
password
:
100Centa30821%mysql
password
:
2018006709
swagger
:
enable
:
true
...
...
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