Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
a0cbabe1
Commit
a0cbabe1
authored
Sep 30, 2020
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成app注册登陆;
完成app补充用户信息
parent
36121f3e
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
365 additions
and
133 deletions
+365
-133
api-app/src/main/java/com/jumeirah/api/app/controller/AppSmsController.java
+5
-5
api-app/src/main/java/com/jumeirah/api/app/controller/AppUserController.java
+26
-10
api-app/src/main/java/com/jumeirah/api/app/service/AppRegisterService.java
+0
-6
api-app/src/main/java/com/jumeirah/api/app/service/AppSmsService.java
+29
-2
api-app/src/main/java/com/jumeirah/api/app/service/AppUserApiService.java
+28
-0
api-app/src/main/java/com/jumeirah/api/app/service/impl/AppRegisterServiceImpl.java
+0
-13
api-app/src/main/java/com/jumeirah/api/app/service/impl/AppSmsServiceImpl.java
+71
-11
api-app/src/main/java/com/jumeirah/api/app/service/impl/AppUserApiServiceImpl.java
+73
-0
api-app/src/main/java/com/jumeirah/api/app/vo/RedisSmsCode.java
+0
-14
api-app/src/main/java/com/jumeirah/api/app/vo/SmsCode.java
+1
-1
common/src/main/java/com/jumeirah/common/entity/AppUser.java
+15
-0
common/src/main/java/com/jumeirah/common/param/app/AppSmsRegisterParam.java
+1
-1
common/src/main/java/com/jumeirah/common/param/app/AppUserInfoParam.java
+46
-0
common/src/main/java/com/jumeirah/common/service/AppUserService.java
+23
-4
common/src/main/java/com/jumeirah/common/service/impl/AppUserServiceImpl.java
+25
-35
common/src/main/java/com/jumeirah/common/service/impl/MerchantUserServiceImpl.java
+1
-1
common/src/main/java/com/jumeirah/common/service/impl/SysLoginServiceImpl.java
+1
-16
common/src/main/java/com/jumeirah/common/vo/app/LoginAppUserTokenVo.java
+3
-5
config/src/main/resources/config/application.yml
+2
-2
framework/src/main/java/io/geekidea/springbootplus/framework/config/il8n/LanguageEnum.java
+4
-3
framework/src/main/java/io/geekidea/springbootplus/framework/shiro/jwt/JwtFilter.java
+8
-2
framework/src/main/java/io/geekidea/springbootplus/framework/shiro/jwt/JwtToken.java
+2
-1
framework/src/main/java/io/geekidea/springbootplus/framework/shiro/service/impl/ShiroLoginServiceImpl.java
+1
-1
No files found.
api-app/src/main/java/com/jumeirah/api/app/controller/AppSmsController.java
View file @
a0cbabe1
...
@@ -34,12 +34,12 @@ public class AppSmsController extends BaseController {
...
@@ -34,12 +34,12 @@ public class AppSmsController extends BaseController {
/**
/**
* 获取注册验证码
* 获取注册验证码
*/
*/
@GetMapping
(
"/register"
)
@GetMapping
(
"/register
OrLoginCode
"
)
@OperationLog
(
name
=
"获取注册验证码"
,
type
=
OperationLogType
.
INFO
)
@OperationLog
(
name
=
"获取注册
或登陆的
验证码"
,
type
=
OperationLogType
.
INFO
)
@ApiOperation
(
value
=
"获取注册验证码"
,
response
=
SmsCode
.
class
,
notes
=
"本地环境默认666666"
)
@ApiOperation
(
value
=
"获取注册
或登陆的
验证码"
,
response
=
SmsCode
.
class
,
notes
=
"本地环境默认666666"
)
public
ApiResult
<
SmsCode
>
register
(
@RequestParam
String
area
,
@RequestParam
String
number
)
throws
Exception
{
public
ApiResult
<
Object
>
register
(
@RequestParam
String
phoneArea
,
@RequestParam
String
phone
)
throws
Exception
{
return
appSmsService
.
registerType
(
area
,
number
);
return
appSmsService
.
registerType
(
phoneArea
,
phone
);
}
}
}
}
...
...
api-app/src/main/java/com/jumeirah/api/app/controller/AppUserController.java
View file @
a0cbabe1
package
com
.
jumeirah
.
api
.
app
.
controller
;
package
com
.
jumeirah
.
api
.
app
.
controller
;
import
com.jumeirah.api.app.service.AppUserApiService
;
import
com.jumeirah.common.entity.AppUser
;
import
com.jumeirah.common.entity.AppUser
;
import
com.jumeirah.common.param.AppUserPageParam
;
import
com.jumeirah.common.param.AppUserPageParam
;
import
com.jumeirah.common.param.LoginParam
;
import
com.jumeirah.common.param.app.AppSmsRegisterParam
;
import
com.jumeirah.common.param.app.AppSmsRegisterParam
;
import
com.jumeirah.common.param.app.AppUserInfoParam
;
import
com.jumeirah.common.service.AppUserService
;
import
com.jumeirah.common.service.AppUserService
;
import
com.jumeirah.common.vo.AppUserQueryVo
;
import
com.jumeirah.common.vo.AppUserQueryVo
;
import
com.jumeirah.common.vo.LoginSysUserTokenVo
;
import
com.jumeirah.common.vo.LoginSysUserTokenVo
;
...
@@ -46,6 +47,20 @@ public class AppUserController extends BaseController {
...
@@ -46,6 +47,20 @@ public class AppUserController extends BaseController {
@Autowired
@Autowired
private
AppUserService
appUserService
;
private
AppUserService
appUserService
;
@Autowired
private
AppUserApiService
appUserApiService
;
/**
* 添加APP用户
*/
@PostMapping
(
"/updateAppUserInfo"
)
// @OperationLog(name = "补充或修改APP用户信息", type = OperationLogType.ADD)
@ApiOperation
(
value
=
"补充或修改APP用户信息"
,
notes
=
"不需要修改的字段传入null"
,
response
=
ApiResult
.
class
)
public
ApiResult
<
Boolean
>
updateAppUserInfo
(
@RequestBody
AppUserInfoParam
appUserInfoParam
)
throws
Exception
{
boolean
flag
=
appUserApiService
.
updateAppUser
(
appUserInfoParam
);
return
ApiResult
.
result
(
flag
);
}
/**
/**
* 添加APP用户
* 添加APP用户
*/
*/
...
@@ -106,17 +121,18 @@ public class AppUserController extends BaseController {
...
@@ -106,17 +121,18 @@ public class AppUserController extends BaseController {
return
ApiResult
.
ok
(
paging
);
return
ApiResult
.
ok
(
paging
);
}
}
@PostMapping
(
"/register"
)
@PostMapping
(
"/register
OrLogin
"
)
@ApiOperation
(
value
=
"手机号注册
"
,
notes
=
"app用户注册
"
,
response
=
LoginSysUserTokenVo
.
class
)
@ApiOperation
(
value
=
"手机号注册
+登陆"
,
notes
=
"app用户注册+登陆
"
,
response
=
LoginSysUserTokenVo
.
class
)
public
ApiResult
<
LoginAppUserTokenVo
>
register
(
@Validated
@RequestBody
AppSmsRegisterParam
appSmsRegisterParam
,
@RequestHeader
(
required
=
false
)
String
language
)
throws
Exception
{
public
ApiResult
<
LoginAppUserTokenVo
>
register
OrLogin
(
@Validated
@RequestBody
AppSmsRegisterParam
appSmsRegisterParam
,
@RequestHeader
(
required
=
false
)
String
language
)
throws
Exception
{
return
appUserService
.
register
(
appSmsRegisterParam
,
language
);
return
appUser
Api
Service
.
register
(
appSmsRegisterParam
,
language
);
}
}
@PostMapping
(
"/login"
)
// @PostMapping("/login")
@ApiOperation
(
value
=
"手机号登陆"
,
notes
=
"app用户登录"
,
response
=
LoginSysUserTokenVo
.
class
)
// @ApiOperation(value = "手机号登陆", notes = "app用户登录", response = LoginSysUserTokenVo.class)
public
ApiResult
<
LoginAppUserTokenVo
>
login
(
@Validated
@RequestBody
AppSmsRegisterParam
loginParam
,
@RequestHeader
(
required
=
false
)
String
language
)
throws
Exception
{
// public ApiResult<LoginAppUserTokenVo> login(@Validated @RequestBody AppSmsRegisterParam loginParam, @RequestHeader(required = false) String language) throws Exception {
return
appUserService
.
login
(
loginParam
,
language
);
//// return appRegisterService.login(loginParam, language);
}
// return null;
// }
}
}
api-app/src/main/java/com/jumeirah/api/app/service/AppRegisterService.java
deleted
100644 → 0
View file @
36121f3e
package
com
.
jumeirah
.
api
.
app
.
service
;
public
interface
AppRegisterService
{
void
regiest
();
}
api-app/src/main/java/com/jumeirah/api/app/service/AppSmsService.java
View file @
a0cbabe1
package
com
.
jumeirah
.
api
.
app
.
service
;
package
com
.
jumeirah
.
api
.
app
.
service
;
import
com.jumeirah.api.app.vo.SmsCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
public
interface
AppSmsService
{
public
interface
AppSmsService
{
void
deleteRegisterCode
(
String
area
,
String
number
);
/**
* 获取注册验证码
*/
ApiResult
<
Object
>
registerType
(
String
phoneArea
,
String
phone
);
/**
/**
* 获取注册验证码
* 获取注册验证码
*/
*/
ApiResult
<
SmsCode
>
registerType
(
String
area
,
String
number
);
ApiResult
LoginType
(
String
area
,
String
number
);
/**
* 校验注册验证码
*
* @param area
* @param number
* @param code
* @return
*/
boolean
equalsRegisterCode
(
String
area
,
String
number
,
String
code
);
/**
* 校验验登陆证码
*
* @param area
* @param number
* @param code
* @return
*/
boolean
equalsLoginCode
(
String
area
,
String
number
,
String
code
);
}
}
api-app/src/main/java/com/jumeirah/api/app/service/AppUserApiService.java
0 → 100644
View file @
a0cbabe1
package
com
.
jumeirah
.
api
.
app
.
service
;
import
com.jumeirah.common.param.app.AppSmsRegisterParam
;
import
com.jumeirah.common.param.app.AppUserInfoParam
;
import
com.jumeirah.common.vo.app.LoginAppUserTokenVo
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
public
interface
AppUserApiService
{
/**
* 注册
* @param loginParam
* @param language
* @return
* @throws Exception
*/
ApiResult
<
LoginAppUserTokenVo
>
register
(
AppSmsRegisterParam
loginParam
,
String
language
)
throws
Exception
;
ApiResult
<
LoginAppUserTokenVo
>
login
(
AppSmsRegisterParam
loginParam
,
String
language
)
throws
Exception
;
/**
* 修改或补充用户信息
* @param appUserInfoParam
* @return
* @throws Exception
*/
boolean
updateAppUser
(
AppUserInfoParam
appUserInfoParam
)
throws
Exception
;
}
api-app/src/main/java/com/jumeirah/api/app/service/impl/AppRegisterServiceImpl.java
deleted
100644 → 0
View file @
36121f3e
package
com
.
jumeirah
.
api
.
app
.
service
.
impl
;
import
com.jumeirah.api.app.service.AppRegisterService
;
import
org.springframework.stereotype.Service
;
@Service
public
class
AppRegisterServiceImpl
implements
AppRegisterService
{
@Override
public
void
regiest
()
{
}
}
api-app/src/main/java/com/jumeirah/api/app/service/impl/AppSmsServiceImpl.java
View file @
a0cbabe1
...
@@ -18,7 +18,7 @@ import java.util.Arrays;
...
@@ -18,7 +18,7 @@ import java.util.Arrays;
public
class
AppSmsServiceImpl
implements
AppSmsService
{
public
class
AppSmsServiceImpl
implements
AppSmsService
{
/**
/**
*
SpringBoot
获取当前环境
* 获取当前环境
*/
*/
@Value
(
"${spring.profiles.active}"
)
@Value
(
"${spring.profiles.active}"
)
private
String
profiles
;
private
String
profiles
;
...
@@ -26,35 +26,95 @@ public class AppSmsServiceImpl implements AppSmsService {
...
@@ -26,35 +26,95 @@ public class AppSmsServiceImpl implements AppSmsService {
@Autowired
@Autowired
private
RedisTemplate
redisTemplate
;
private
RedisTemplate
redisTemplate
;
private
static
final
String
SMS_REGIEST
=
"sms:register:%s:%s"
;
/**
* 测试环境
*/
private
static
final
String
DEV_PROFILE
=
"dev"
;
/**
* 测试环境默认短信验证码
*/
private
static
final
String
DEFAULT_DEV_SMS_CODE
=
"666666"
;
/**
* 短信验证码redis的key值
*/
private
static
final
String
SMS_REGIEST
=
"sms:register:%s_%s"
;
/**
* 短信验证码redis的key值
*/
private
static
final
String
SMS_LOGIN
=
"sms:login:%s_%s"
;
@Override
public
void
deleteRegisterCode
(
String
area
,
String
number
)
{
redisTemplate
.
delete
(
String
.
format
(
SMS_REGIEST
,
area
,
number
));
}
@Override
@Override
public
ApiResult
<
SmsCode
>
registerType
(
String
area
,
String
number
)
{
public
ApiResult
<
Object
>
registerType
(
String
area
,
String
number
)
{
return
getSmsCodeApiResult
(
String
.
format
(
SMS_REGIEST
,
area
,
number
),
area
,
number
);
}
private
ApiResult
<
Object
>
getSmsCodeApiResult
(
String
key
,
String
area
,
String
number
)
{
String
randomCode
=
getRandomCode
();
String
randomCode
=
getRandomCode
();
//
存入redis
//
过期时间(秒)
long
expire
=
120L
;
long
expire
=
120L
;
Duration
expireDuration
=
Duration
.
ofSeconds
(
expire
);
Duration
expireDuration
=
Duration
.
ofSeconds
(
expire
);
redisTemplate
.
opsForValue
().
set
(
String
.
format
(
SMS_REGIEST
,
area
,
number
)
,
randomCode
,
expireDuration
);
redisTemplate
.
opsForValue
().
set
(
key
,
randomCode
,
expireDuration
);
SmsCode
smsCode
=
new
SmsCode
();
SmsCode
smsCode
=
new
SmsCode
();
smsCode
.
setCode
(
randomCode
);
smsCode
.
setSmsCode
(
randomCode
);
log
.
info
(
area
+
","
+
number
+
":"
+
randomCode
);
log
.
info
(
area
+
","
+
number
+
":"
+
randomCode
);
// TODO 需要补充调用发送代码
// TODO 需要补充调用短信平台发送短信代码 2020年09月30日09:48:42
return
ApiResult
.
ok
(
null
);
}
@Override
public
ApiResult
LoginType
(
String
area
,
String
number
)
{
return
getSmsCodeApiResult
(
String
.
format
(
SMS_LOGIN
,
area
,
number
),
area
,
number
);
}
@Override
public
boolean
equalsRegisterCode
(
String
area
,
String
number
,
String
code
)
{
return
equalsSms
(
SMS_REGIEST
,
area
,
number
,
code
);
}
private
boolean
equalsSms
(
String
type
,
String
area
,
String
number
,
String
code
)
{
String
formatKey
=
String
.
format
(
type
,
area
,
number
);
Object
key
=
redisTemplate
.
opsForValue
().
get
(
formatKey
);
return
ApiResult
.
ok
(
smsCode
);
if
(
key
==
null
)
{
return
false
;
}
return
String
.
valueOf
(
key
).
equals
(
code
);
}
@Override
public
boolean
equalsLoginCode
(
String
area
,
String
number
,
String
code
)
{
return
equalsSms
(
SMS_LOGIN
,
area
,
number
,
code
);
}
}
/**
* 生成验证码code
*
* @return
*/
String
getRandomCode
()
{
String
getRandomCode
()
{
// 如果为测试环境则生成默认
// 如果为测试环境则生成默认
if
(
profiles
.
equals
(
"dev"
))
{
if
(
profiles
.
equals
(
DEV_PROFILE
))
{
return
"666666"
;
return
DEFAULT_DEV_SMS_CODE
;
}
else
{
}
else
{
return
Arrays
.
toString
(
RandomUtil
.
randomInts
(
6
));
return
Arrays
.
toString
(
RandomUtil
.
randomInts
(
6
));
}
}
}
}
}
}
api-app/src/main/java/com/jumeirah/api/app/service/impl/AppUserApiServiceImpl.java
0 → 100644
View file @
a0cbabe1
package
com
.
jumeirah
.
api
.
app
.
service
.
impl
;
import
com.jumeirah.api.app.service.AppSmsService
;
import
com.jumeirah.api.app.service.AppUserApiService
;
import
com.jumeirah.common.entity.AppUser
;
import
com.jumeirah.common.param.app.AppSmsRegisterParam
;
import
com.jumeirah.common.param.app.AppUserInfoParam
;
import
com.jumeirah.common.service.AppUserService
;
import
com.jumeirah.common.vo.app.LoginAppUserTokenVo
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.shiro.jwt.JwtToken
;
import
org.apache.shiro.SecurityUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
public
class
AppUserApiServiceImpl
implements
AppUserApiService
{
@Autowired
private
AppSmsService
appSmsService
;
@Autowired
private
AppUserService
appUserService
;
@Override
public
ApiResult
<
LoginAppUserTokenVo
>
register
(
AppSmsRegisterParam
loginParam
,
String
language
)
throws
Exception
{
// 校验验证码
boolean
equalsRegisterCode
=
appSmsService
.
equalsRegisterCode
(
loginParam
.
getPhoneArea
(),
loginParam
.
getPhone
(),
loginParam
.
getSmsCode
());
if
(!
equalsRegisterCode
)
{
return
ApiResult
.
fail
(
ApiCode
.
FAIL
,
new
LoginAppUserTokenVo
());
}
// 删除已使用的验证码
appSmsService
.
deleteRegisterCode
(
loginParam
.
getPhoneArea
(),
loginParam
.
getPhone
());
// 判断是否已经注册
if
(
appUserService
.
hasUserByPhoneNumer
(
loginParam
.
getPhoneArea
(),
loginParam
.
getPhone
()))
{
// 如果已经注册直接走登陆的代码
return
appUserService
.
login
(
loginParam
,
language
);
}
// 没注册则先保存到数据库
AppUser
appUser
=
new
AppUser
();
appUser
.
setPhoneArea
(
loginParam
.
getPhoneArea
());
appUser
.
setPhone
(
loginParam
.
getPhone
());
boolean
isDbOk
=
appUserService
.
saveAppUser
(
appUser
);
if
(!
isDbOk
)
{
return
ApiResult
.
fail
(
ApiCode
.
FAIL
,
new
LoginAppUserTokenVo
());
}
// 走登陆的代码
return
appUserService
.
login
(
loginParam
,
language
);
}
@Override
public
ApiResult
<
LoginAppUserTokenVo
>
login
(
AppSmsRegisterParam
loginParam
,
String
language
)
throws
Exception
{
return
null
;
}
@Override
public
boolean
updateAppUser
(
AppUserInfoParam
appUserInfoParam
)
throws
Exception
{
AppUser
appUser
=
new
AppUser
();
BeanUtils
.
copyProperties
(
appUserInfoParam
,
appUser
);
JwtToken
jwtToken
=
(
JwtToken
)
SecurityUtils
.
getSubject
().
getPrincipal
();
appUser
.
setId
(
jwtToken
.
getUserId
());
return
appUserService
.
updateAppUser
(
appUser
);
}
}
api-app/src/main/java/com/jumeirah/api/app/vo/RedisSmsCode.java
deleted
100644 → 0
View file @
36121f3e
package
com
.
jumeirah
.
api
.
app
.
vo
;
import
lombok.Data
;
import
java.io.Serializable
;
@Data
public
class
RedisSmsCode
implements
Serializable
{
private
String
code
;
private
String
area
;
private
String
number
;
}
api-app/src/main/java/com/jumeirah/api/app/vo/SmsCode.java
View file @
a0cbabe1
...
@@ -7,5 +7,5 @@ import java.io.Serializable;
...
@@ -7,5 +7,5 @@ import java.io.Serializable;
@Data
@Data
public
class
SmsCode
implements
Serializable
{
public
class
SmsCode
implements
Serializable
{
private
String
c
ode
;
private
String
smsC
ode
;
}
}
common/src/main/java/com/jumeirah/common/entity/AppUser.java
View file @
a0cbabe1
...
@@ -37,6 +37,21 @@ public class AppUser extends BaseEntity {
...
@@ -37,6 +37,21 @@ public class AppUser extends BaseEntity {
@ApiModelProperty
(
"用户名"
)
@ApiModelProperty
(
"用户名"
)
private
String
username
;
private
String
username
;
@ApiModelProperty
(
"姓"
)
private
String
surname
;
@ApiModelProperty
(
"名"
)
private
String
name
;
@ApiModelProperty
(
"公司名"
)
private
String
companyName
;
@ApiModelProperty
(
"微信号"
)
private
String
wechat
;
@ApiModelProperty
(
"出生日期"
)
private
String
dateOfBirth
;
@ApiModelProperty
(
"昵称"
)
@ApiModelProperty
(
"昵称"
)
private
String
nickname
;
private
String
nickname
;
...
...
common/src/main/java/com/jumeirah/common/param/app/AppSmsRegisterParam.java
View file @
a0cbabe1
...
@@ -41,6 +41,6 @@ public class AppSmsRegisterParam implements Serializable {
...
@@ -41,6 +41,6 @@ public class AppSmsRegisterParam implements Serializable {
@ApiModelProperty
(
value
=
"手机号"
,
example
=
"081611122"
)
@ApiModelProperty
(
value
=
"手机号"
,
example
=
"081611122"
)
private
String
phone
;
private
String
phone
;
@ApiModelProperty
(
"短信验证码
"
)
@ApiModelProperty
(
value
=
"短信验证码"
,
example
=
"666666
"
)
private
String
smsCode
;
private
String
smsCode
;
}
}
common/src/main/java/com/jumeirah/common/param/app/AppUserInfoParam.java
0 → 100644
View file @
a0cbabe1
package
com
.
jumeirah
.
common
.
param
.
app
;
import
io.geekidea.springbootplus.framework.common.entity.BaseEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
/**
* APP用户
*
* @author wei
* @since 2020-09-23
*/
@Data
@Accessors
(
chain
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"AppUserInfoParam对象"
)
public
class
AppUserInfoParam
extends
BaseEntity
{
@ApiModelProperty
(
"姓"
)
private
String
surname
;
@ApiModelProperty
(
"名"
)
private
String
name
;
@ApiModelProperty
(
"公司名"
)
private
String
companyName
;
@ApiModelProperty
(
"微信号"
)
private
String
wechat
;
@ApiModelProperty
(
"出生日期"
)
private
String
dateOfBirth
;
@ApiModelProperty
(
"昵称"
)
private
String
nickname
;
@ApiModelProperty
(
"性别,0:女,1:男,默认1"
)
private
Integer
gender
;
@ApiModelProperty
(
"头像"
)
private
String
head
;
}
common/src/main/java/com/jumeirah/common/service/AppUserService.java
View file @
a0cbabe1
...
@@ -2,10 +2,8 @@ package com.jumeirah.common.service;
...
@@ -2,10 +2,8 @@ package com.jumeirah.common.service;
import
com.jumeirah.common.entity.AppUser
;
import
com.jumeirah.common.entity.AppUser
;
import
com.jumeirah.common.param.AppUserPageParam
;
import
com.jumeirah.common.param.AppUserPageParam
;
import
com.jumeirah.common.param.RegisterParam
;
import
com.jumeirah.common.param.app.AppSmsRegisterParam
;
import
com.jumeirah.common.param.app.AppSmsRegisterParam
;
import
com.jumeirah.common.vo.AppUserQueryVo
;
import
com.jumeirah.common.vo.AppUserQueryVo
;
import
com.jumeirah.common.vo.LoginSysUserTokenVo
;
import
com.jumeirah.common.vo.app.LoginAppUserTokenVo
;
import
com.jumeirah.common.vo.app.LoginAppUserTokenVo
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.service.BaseService
;
import
io.geekidea.springbootplus.framework.common.service.BaseService
;
...
@@ -19,10 +17,31 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging;
...
@@ -19,10 +17,31 @@ import io.geekidea.springbootplus.framework.core.pagination.Paging;
*/
*/
public
interface
AppUserService
extends
BaseService
<
AppUser
>
{
public
interface
AppUserService
extends
BaseService
<
AppUser
>
{
ApiResult
<
LoginAppUserTokenVo
>
register
(
AppSmsRegisterParam
appSmsRegisterParam
,
String
language
);
/**
* 根据手机号判断用户是否存在
* @param phoneArea
* @param phone
* @return
*/
boolean
hasUserByPhoneNumer
(
String
phoneArea
,
String
phone
);
ApiResult
<
LoginAppUserTokenVo
>
login
(
AppSmsRegisterParam
loginParam
,
String
language
);
// /**
// * 注册
// *
// * @param appSmsRegisterParam
// * @param language
// * @return
// */
// ApiResult<LoginAppUserTokenVo> register(AppSmsRegisterParam appSmsRegisterParam, String language);
/**
* 登陆
*
* @param loginParam
* @param language
* @return
*/
ApiResult
<
LoginAppUserTokenVo
>
login
(
AppSmsRegisterParam
loginParam
,
String
language
);
/**
/**
...
...
common/src/main/java/com/jumeirah/common/service/impl/AppUserServiceImpl.java
View file @
a0cbabe1
...
@@ -66,61 +66,54 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
...
@@ -66,61 +66,54 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
private
AppUserMapper
appUserMapper
;
private
AppUserMapper
appUserMapper
;
@Override
@Override
public
ApiResult
<
LoginAppUserTokenVo
>
register
(
AppSmsRegisterParam
appSmsRegisterParam
,
String
language
)
{
public
boolean
hasUserByPhoneNumer
(
String
phoneArea
,
String
phone
)
{
// JwtToken jwtToken = (JwtToken) SecurityUtils.getSubject().getPrincipal();
Integer
selectCount
=
appUserMapper
.
selectCount
(
new
QueryWrapper
<
AppUser
>(
new
AppUser
().
setPhoneArea
(
phoneArea
).
setPhone
(
phone
)
// 校验短信验证码是否正确
));
return
selectCount
>
0
;
return
null
;
}
}
@Override
// @Override
public
ApiResult
<
LoginAppUserTokenVo
>
login
(
AppSmsRegisterParam
loginParam
,
String
language
){
// public ApiResult<LoginAppUserTokenVo> register(AppSmsRegisterParam appSmsRegisterParam, String language) {
//// JwtToken jwtToken = (JwtToken) SecurityUtils.getSubject().getPrincipal();
//
// 校验验证码
// // 校验短信验证码是否正确
//
// checkVerifyCode(loginParam.getVerifyToken(), loginParam.getCode());
// return null;
// }
String
username
=
loginParam
.
getPhone
();
@Override
public
ApiResult
<
LoginAppUserTokenVo
>
login
(
AppSmsRegisterParam
loginParam
,
String
language
)
{
// 从数据库中获取登录用户信息
// 从数据库中获取登录用户信息
AppUser
appUser
=
appUserMapper
.
selectOne
(
new
QueryWrapper
<
AppUser
>(
new
AppUser
().
setUsername
(
username
)));
AppUser
appUser
=
appUserMapper
.
selectOne
(
new
QueryWrapper
<>(
new
AppUser
().
setPhoneArea
(
loginParam
.
getPhoneArea
()).
setPhone
(
loginParam
.
getPhone
()))
);
if
(
appUser
==
null
)
{
if
(
appUser
==
null
)
{
log
.
error
(
"登录失败,用户名或密码错误 loginParam:{}"
,
loginParam
);
log
.
error
(
"登录失败,loginParam:{}"
,
loginParam
);
// throw new AuthenticationException("用户名或密码错误");
return
ApiResult
.
fail
(
ApiCode
.
PWD_OR_USERNAME_ERROR
,
language
);
return
ApiResult
.
fail
(
ApiCode
.
PWD_OR_USERNAME_ERROR
,
language
);
}
}
if
(
StateEnum
.
DISABLE
.
getCode
().
equals
(
appUser
.
getState
()))
{
if
(
StateEnum
.
DISABLE
.
getCode
().
equals
(
appUser
.
getState
()))
{
throw
new
AuthenticationException
(
"账号已禁用"
);
throw
new
AuthenticationException
(
"账号已禁用"
);
}
}
// 实际项目中,前端传过来的密码应先加密
// 原始密码明文:123456
// 原始密码前端加密:sha256(123456)
// 后台加密规则:sha256(sha256(123456) + salt)
// String encryptPassword = PasswordUtil.encrypt(loginParam.getPassword(), appUser.getSalt());
// if (!encryptPassword.equals(appUser.getPassword())) {
// return ApiResult.fail(ApiCode.PWD_OR_USERNAME_ERROR, language);
// }
// 将系统用户对象转换成登录用户对象
// 将系统用户对象转换成登录用户对象
LoginUserVo
loginSysUserVo
=
new
LoginUserVo
();
LoginUserVo
loginSysUserVo
=
new
LoginUserVo
();
loginSysUserVo
.
setUsername
(
username
);
loginSysUserVo
.
setId
(
appUser
.
getId
());
loginSysUserVo
.
setUsername
(
appUser
.
getId
().
toString
());
// 获取数据库中保存的盐值
// 获取数据库中保存的盐值
String
newSalt
=
SaltUtil
.
getSalt
(
appUser
.
getSalt
(),
jwtProperties
);
String
newSalt
=
SaltUtil
.
getSalt
(
appUser
.
getSalt
(),
jwtProperties
);
// 生成token字符串并返回
// 生成token字符串并返回
Long
expireSecond
=
jwtProperties
.
getExpireSecond
();
Long
expireSecond
=
jwtProperties
.
getExpireSecond
();
String
token
=
JwtUtil
.
generateToken
(
username
,
newSalt
,
Duration
.
ofSeconds
(
expireSecond
));
String
token
=
JwtUtil
.
generateToken
(
appUser
.
getId
().
toString
()
,
newSalt
,
Duration
.
ofSeconds
(
expireSecond
));
log
.
debug
(
"token:{}"
,
token
);
log
.
debug
(
"token:{}"
,
token
);
// 创建AuthenticationToken
// 创建AuthenticationToken
JwtToken
jwtToken
=
JwtToken
.
build
(
token
,
username
,
newSalt
,
expireSecond
,
"app"
);
JwtToken
jwtToken
=
JwtToken
.
build
(
token
,
appUser
.
getId
().
toString
(),
appUser
.
getId
()
,
newSalt
,
expireSecond
,
"app"
);
boolean
enableShiro
=
springBootPlusProperties
.
getShiro
().
isEnable
();
boolean
enableShiro
=
springBootPlusProperties
.
getShiro
().
isEnable
();
if
(
enableShiro
)
{
if
(
enableShiro
)
{
...
@@ -134,7 +127,7 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
...
@@ -134,7 +127,7 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
// 缓存登录信息到Redis
// 缓存登录信息到Redis
appLoginRedisService
.
cacheLoginInfo
(
jwtToken
,
loginSysUserVo
);
appLoginRedisService
.
cacheLoginInfo
(
jwtToken
,
loginSysUserVo
);
log
.
debug
(
"登录成功,
username:{}"
,
username
);
log
.
debug
(
"登录成功,
id:{}"
,
appUser
.
getId
().
toString
()
);
// 缓存登录信息到redis
// 缓存登录信息到redis
String
tokenSha256
=
DigestUtils
.
sha256Hex
(
token
);
String
tokenSha256
=
DigestUtils
.
sha256Hex
(
token
);
...
@@ -143,14 +136,11 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
...
@@ -143,14 +136,11 @@ public class AppUserServiceImpl extends BaseServiceImpl<AppUserMapper, AppUser>
// 返回token和登录用户信息对象
// 返回token和登录用户信息对象
LoginAppUserTokenVo
loginSysUserTokenVo
=
new
LoginAppUserTokenVo
();
LoginAppUserTokenVo
loginSysUserTokenVo
=
new
LoginAppUserTokenVo
();
loginSysUserTokenVo
.
setToken
(
token
);
loginSysUserTokenVo
.
setToken
(
token
);
loginSysUserTokenVo
.
setUserId
(
appUser
.
getId
());
return
ApiResult
.
ok
(
loginSysUserTokenVo
,
language
);
return
ApiResult
.
ok
(
loginSysUserTokenVo
,
language
);
}
}
// @Override
// public ApiResult<LoginSysUserTokenVo> phoneLogin(RegisterParam registerParam, String language) {
// return null;
// }
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
@Override
...
...
common/src/main/java/com/jumeirah/common/service/impl/MerchantUserServiceImpl.java
View file @
a0cbabe1
...
@@ -156,7 +156,7 @@ public class MerchantUserServiceImpl extends BaseServiceImpl<MerchantUserMapper,
...
@@ -156,7 +156,7 @@ public class MerchantUserServiceImpl extends BaseServiceImpl<MerchantUserMapper,
log
.
debug
(
"token:{}"
,
token
);
log
.
debug
(
"token:{}"
,
token
);
// 创建AuthenticationToken
// 创建AuthenticationToken
JwtToken
jwtToken
=
JwtToken
.
build
(
token
,
username
,
newSalt
,
expireSecond
,
"mer"
);
JwtToken
jwtToken
=
JwtToken
.
build
(
token
,
username
,
merchantUser
.
getId
(),
newSalt
,
expireSecond
,
"mer"
);
boolean
enableShiro
=
springBootPlusProperties
.
getShiro
().
isEnable
();
boolean
enableShiro
=
springBootPlusProperties
.
getShiro
().
isEnable
();
if
(
enableShiro
)
{
if
(
enableShiro
)
{
...
...
common/src/main/java/com/jumeirah/common/service/impl/SysLoginServiceImpl.java
View file @
a0cbabe1
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
jumeirah
.
common
.
service
.
impl
;
package
com
.
jumeirah
.
common
.
service
.
impl
;
...
@@ -176,7 +161,7 @@ public class SysLoginServiceImpl implements SysLoginService {
...
@@ -176,7 +161,7 @@ public class SysLoginServiceImpl implements SysLoginService {
log
.
debug
(
"token:{}"
,
token
);
log
.
debug
(
"token:{}"
,
token
);
// 创建AuthenticationToken
// 创建AuthenticationToken
JwtToken
jwtToken
=
JwtToken
.
build
(
token
,
username
,
newSalt
,
expireSecond
,
"sys"
);
JwtToken
jwtToken
=
JwtToken
.
build
(
token
,
username
,
sysUser
.
getId
(),
newSalt
,
expireSecond
,
"sys"
);
boolean
enableShiro
=
springBootPlusProperties
.
getShiro
().
isEnable
();
boolean
enableShiro
=
springBootPlusProperties
.
getShiro
().
isEnable
();
if
(
enableShiro
)
{
if
(
enableShiro
)
{
...
...
common/src/main/java/com/jumeirah/common/vo/app/LoginAppUserTokenVo.java
View file @
a0cbabe1
...
@@ -31,19 +31,17 @@ import lombok.experimental.Accessors;
...
@@ -31,19 +31,17 @@ import lombok.experimental.Accessors;
@ApiModel
(
"登录用户信息TokenVO"
)
@ApiModel
(
"登录用户信息TokenVO"
)
public
class
LoginAppUserTokenVo
implements
LoginToken
{
public
class
LoginAppUserTokenVo
implements
LoginToken
{
private
static
final
long
serialVersionUID
=
-
2138450422989081056L
;
@ApiModelProperty
(
"token"
)
@ApiModelProperty
(
"token"
)
private
String
token
;
private
String
token
;
@ApiModelProperty
(
"主键"
)
@ApiModelProperty
(
"主键"
)
private
Long
i
d
;
private
Long
userI
d
;
@ApiModelProperty
(
"用户名"
)
@ApiModelProperty
(
"用户名"
)
private
String
username
;
private
String
username
;
@ApiModelProperty
(
"昵称"
)
//
@ApiModelProperty("昵称")
private
String
nickname
;
//
private String nickname;
// /**
// /**
// * 登录用户对象
// * 登录用户对象
...
...
config/src/main/resources/config/application.yml
View file @
a0cbabe1
...
@@ -183,10 +183,10 @@ spring-boot-plus:
...
@@ -183,10 +183,10 @@ spring-boot-plus:
# 权限配置
# 权限配置
anon
:
anon
:
# 排除登录 注册 登出
# 排除登录 注册 登出
-
/app/user/register
,/app/user/phone
Login,/app/user/login
-
/app/user/register
Or
Login,/app/user/login
-
/sys/login,/sys/logout,/sys/register
-
/sys/login,/sys/logout,/sys/register
-
/merchantUser/login
-
/merchantUser/login
-
/app/sms/register
-
/app/sms/register
OrLoginCode
# 排除静态资源
# 排除静态资源
-
/static/**,/templates/**
-
/static/**,/templates/**
# 排除Swagger
# 排除Swagger
...
...
framework/src/main/java/io/geekidea/springbootplus/framework/config/il8n/LanguageEnum.java
View file @
a0cbabe1
...
@@ -34,21 +34,22 @@ public enum LanguageEnum {
...
@@ -34,21 +34,22 @@ public enum LanguageEnum {
/**
/**
* 获取指定语言类型(如果没有对应的语言类型,则返回
英
文)
* 获取指定语言类型(如果没有对应的语言类型,则返回
中
文)
*
*
* @param language 语言类型
* @param language 语言类型
* @return
* @return
*/
*/
public
static
String
getLanguageType
(
String
language
)
{
public
static
String
getLanguageType
(
String
language
)
{
// 设置默认为中文
if
(
StringUtils
.
isEmpty
(
language
))
{
if
(
StringUtils
.
isEmpty
(
language
))
{
return
LANGUAGE_
EN_US
.
language
;
return
LANGUAGE_
ZH_CN
.
language
;
}
}
for
(
LanguageEnum
languageEnum
:
LanguageEnum
.
values
())
{
for
(
LanguageEnum
languageEnum
:
LanguageEnum
.
values
())
{
if
(
languageEnum
.
language
.
equalsIgnoreCase
(
language
))
{
if
(
languageEnum
.
language
.
equalsIgnoreCase
(
language
))
{
return
languageEnum
.
language
;
return
languageEnum
.
language
;
}
}
}
}
return
LANGUAGE_
EN_US
.
language
;
return
LANGUAGE_
ZH_CN
.
language
;
}
}
}
}
framework/src/main/java/io/geekidea/springbootplus/framework/shiro/jwt/JwtFilter.java
View file @
a0cbabe1
...
@@ -95,6 +95,12 @@ public class JwtFilter extends AuthenticatingFilter {
...
@@ -95,6 +95,12 @@ public class JwtFilter extends AuthenticatingFilter {
}
}
}
}
JwtTokenRedisVo
jwt
=
(
JwtTokenRedisVo
)
jwtTokenRedisVo
;
if
(
jwt
==
null
)
{
throw
new
AuthenticationException
(
"Redis Token不存在,token:"
+
token
);
}
String
username
=
JwtUtil
.
getUsername
(
token
);
String
username
=
JwtUtil
.
getUsername
(
token
);
String
salt
;
String
salt
;
...
@@ -103,8 +109,8 @@ public class JwtFilter extends AuthenticatingFilter {
...
@@ -103,8 +109,8 @@ public class JwtFilter extends AuthenticatingFilter {
}
else
{
}
else
{
salt
=
jwtProperties
.
getSecret
();
salt
=
jwtProperties
.
getSecret
();
}
}
JwtTokenRedisVo
jwt
=
(
JwtTokenRedisVo
)
jwtTokenRedisVo
;
return
JwtToken
.
build
(
token
,
username
,
salt
,
jwtProperties
.
getExpireSecond
(),
jwt
.
getType
());
return
JwtToken
.
build
(
token
,
username
,
jwt
.
getUserId
(),
salt
,
jwtProperties
.
getExpireSecond
(),
jwt
.
getType
());
}
}
/**
/**
...
...
framework/src/main/java/io/geekidea/springbootplus/framework/shiro/jwt/JwtToken.java
View file @
a0cbabe1
...
@@ -78,12 +78,13 @@ public class JwtToken implements HostAuthenticationToken {
...
@@ -78,12 +78,13 @@ public class JwtToken implements HostAuthenticationToken {
private
String
credentials
;
private
String
credentials
;
public
static
JwtToken
build
(
String
token
,
String
username
,
String
salt
,
long
expireSecond
,
String
type
)
{
public
static
JwtToken
build
(
String
token
,
String
username
,
Long
userId
,
String
salt
,
long
expireSecond
,
String
type
)
{
DecodedJWT
decodedJwt
=
JwtUtil
.
getJwtInfo
(
token
);
DecodedJWT
decodedJwt
=
JwtUtil
.
getJwtInfo
(
token
);
Date
createDate
=
decodedJwt
.
getIssuedAt
();
Date
createDate
=
decodedJwt
.
getIssuedAt
();
Date
expireDate
=
decodedJwt
.
getExpiresAt
();
Date
expireDate
=
decodedJwt
.
getExpiresAt
();
return
new
JwtToken
()
return
new
JwtToken
()
.
setUsername
(
username
)
.
setUsername
(
username
)
.
setUserId
(
userId
)
.
setToken
(
token
)
.
setToken
(
token
)
.
setHost
(
IpUtil
.
getRequestIp
())
.
setHost
(
IpUtil
.
getRequestIp
())
.
setSalt
(
salt
)
.
setSalt
(
salt
)
...
...
framework/src/main/java/io/geekidea/springbootplus/framework/shiro/service/impl/ShiroLoginServiceImpl.java
View file @
a0cbabe1
...
@@ -103,7 +103,7 @@ public class ShiroLoginServiceImpl implements ShiroLoginService {
...
@@ -103,7 +103,7 @@ public class ShiroLoginServiceImpl implements ShiroLoginService {
// 生成新token字符串
// 生成新token字符串
String
newToken
=
JwtUtil
.
generateToken
(
username
,
salt
,
Duration
.
ofSeconds
(
expireSecond
));
String
newToken
=
JwtUtil
.
generateToken
(
username
,
salt
,
Duration
.
ofSeconds
(
expireSecond
));
// 生成新JwtToken对象
// 生成新JwtToken对象
JwtToken
newJwtToken
=
JwtToken
.
build
(
newToken
,
username
,
salt
,
expireSecond
,
jwtToken
.
getType
());
JwtToken
newJwtToken
=
JwtToken
.
build
(
newToken
,
username
,
jwtToken
.
getUserId
(),
salt
,
expireSecond
,
jwtToken
.
getType
());
// 更新redis缓存
// 更新redis缓存
sysLoginRedisService
.
refreshLoginInfo
(
token
,
username
,
newJwtToken
);
sysLoginRedisService
.
refreshLoginInfo
(
token
,
username
,
newJwtToken
);
log
.
debug
(
"刷新token成功,原token:{},新token:{}"
,
token
,
newToken
);
log
.
debug
(
"刷新token成功,原token:{},新token:{}"
,
token
,
newToken
);
...
...
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