Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-parent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1d435427
authored
Apr 27, 2021
by
zhoujinghao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
app 登录jwt提交
1 parent
0194e6f2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
19 deletions
nafmii-app/src/main/java/org/nafmii/app/user/service/impl/UserServiceImpl.java
nafmii-app/src/main/java/org/nafmii/app/user/vo/UserVO.java
nafmii-common/src/main/java/org/nafmii/common/utils/JwtUtils.java
nafmii-common/src/main/java/org/nafmii/common/vo/AppUser.java
nafmii-common/src/main/java/org/nafmii/common/vo/UserJwtVO.java
nafmii-app/src/main/java/org/nafmii/app/user/service/impl/UserServiceImpl.java
View file @
1d43542
...
@@ -15,6 +15,7 @@ import org.nafmii.common.utils.GuavaUtil;
...
@@ -15,6 +15,7 @@ import org.nafmii.common.utils.GuavaUtil;
import
org.nafmii.common.utils.JwtUtils
;
import
org.nafmii.common.utils.JwtUtils
;
import
org.nafmii.common.utils.SnowFlakeUtil
;
import
org.nafmii.common.utils.SnowFlakeUtil
;
import
org.nafmii.common.constant.UserEnum
;
import
org.nafmii.common.constant.UserEnum
;
import
org.nafmii.common.vo.UserJwtVO
;
import
org.nafmii.enums.RedisEnum
;
import
org.nafmii.enums.RedisEnum
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
...
@@ -119,7 +120,6 @@ public class UserServiceImpl implements UserService {
...
@@ -119,7 +120,6 @@ public class UserServiceImpl implements UserService {
if
(!
code
.
equals
(
registerDto
.
getCode
())){
if
(!
code
.
equals
(
registerDto
.
getCode
())){
throw
new
BusinessException
(
"验证码错误请重新输入"
);
throw
new
BusinessException
(
"验证码错误请重新输入"
);
}
}
int
i
=
appUserMapper
.
insert
(
appUser
);
int
i
=
appUserMapper
.
insert
(
appUser
);
if
(
i
<
0
){
if
(
i
<
0
){
return
new
ApiResponse
().
fail
(
"新增失败"
);
return
new
ApiResponse
().
fail
(
"新增失败"
);
...
@@ -158,6 +158,11 @@ public class UserServiceImpl implements UserService {
...
@@ -158,6 +158,11 @@ public class UserServiceImpl implements UserService {
throw
new
BusinessException
(
"请先注册"
);
throw
new
BusinessException
(
"请先注册"
);
}
}
}
}
UserJwtVO
vo
=
new
UserJwtVO
();
vo
.
setId
(
userVo
.
getId
());
vo
.
setPhone
(
userVo
.
getPhone
());
String
token
=
JwtUtils
.
generateJsonWebToken
(
vo
);
userVo
.
setAuthorization
(
token
);
ApiResponse
apiResponse
=
new
ApiResponse
();
ApiResponse
apiResponse
=
new
ApiResponse
();
apiResponse
.
setData
(
userVo
);
apiResponse
.
setData
(
userVo
);
return
apiResponse
;
return
apiResponse
;
...
...
nafmii-app/src/main/java/org/nafmii/app/user/vo/UserVO.java
View file @
1d43542
...
@@ -64,4 +64,6 @@ public class UserVO {
...
@@ -64,4 +64,6 @@ public class UserVO {
@ApiModelProperty
(
value
=
"是否有效标识 0 有效用户 1无效用户"
)
@ApiModelProperty
(
value
=
"是否有效标识 0 有效用户 1无效用户"
)
private
String
isEnable
;
private
String
isEnable
;
@ApiModelProperty
(
value
=
"token"
)
private
String
authorization
;
}
}
nafmii-common/src/main/java/org/nafmii/common/utils/JwtUtils.java
View file @
1d43542
...
@@ -3,6 +3,7 @@ package org.nafmii.common.utils;
...
@@ -3,6 +3,7 @@ package org.nafmii.common.utils;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
io.jsonwebtoken.SignatureAlgorithm
;
import
org.nafmii.common.vo.UserJwtVO
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -19,24 +20,24 @@ public class JwtUtils {
...
@@ -19,24 +20,24 @@ public class JwtUtils {
private
static
final
String
ROLE_CLAIMS
=
"rol"
;
private
static
final
String
ROLE_CLAIMS
=
"rol"
;
// public static String generateJsonWebToken(AppUser
user) {
public
static
String
generateJsonWebToken
(
UserJwtVO
user
)
{
//
if (user.getId() == null || user.getUserName() == null ) {
if
(
user
.
getId
()
==
null
||
user
.
getUserName
()
==
null
)
{
//
return null;
return
null
;
//
}
}
//
//
Map<String,Object> map = new HashMap<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
//
map.put(ROLE_CLAIMS, "rol");
map
.
put
(
ROLE_CLAIMS
,
"rol"
);
//
String token = Jwts
String
token
=
Jwts
//
.builder()
.
builder
()
//
.setSubject(SUBJECT)
.
setSubject
(
SUBJECT
)
//
.setClaims(map)
.
setClaims
(
map
)
//
.claim("id", user.getId())
.
claim
(
"id"
,
user
.
getId
())
//
.claim("name", user.getUserName())
.
claim
(
"name"
,
user
.
getUserName
())
//
.setIssuedAt(new Date())
.
setIssuedAt
(
new
Date
())
//
.setExpiration(new Date(System.currentTimeMillis() + EXPIRITION))
.
setExpiration
(
new
Date
(
System
.
currentTimeMillis
()
+
EXPIRITION
))
//
.signWith(SignatureAlgorithm.HS256, APPSECRET_KEY).compact();
.
signWith
(
SignatureAlgorithm
.
HS256
,
APPSECRET_KEY
).
compact
();
//
return token;
return
token
;
//
}
}
/**
/**
* 生成token
* 生成token
...
...
nafmii-common/src/main/java/org/nafmii/common/vo/AppUser.java
deleted
100644 → 0
View file @
0194e6f
File mode changed
nafmii-common/src/main/java/org/nafmii/common/vo/UserJwtVO.java
0 → 100644
View file @
1d43542
package
org
.
nafmii
.
common
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.Date
;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/25 10:22
* @ClassName:
* @version:
* @remark:
*/
@Data
@ApiModel
(
"用户返回报文"
)
public
class
UserJwtVO
{
private
Long
id
;
@ApiModelProperty
(
value
=
"昵称"
)
private
String
userName
;
@ApiModelProperty
(
value
=
"登录密码"
)
private
String
loginPwd
;
@ApiModelProperty
(
value
=
"中文姓名"
)
private
String
realName
;
@ApiModelProperty
(
value
=
"手机号/登录账号"
)
private
String
phone
;
@ApiModelProperty
(
value
=
"出生日期"
)
private
String
birthday
;
@ApiModelProperty
(
value
=
"邮箱"
)
private
String
email
;
@ApiModelProperty
(
value
=
"头像图片地址"
)
private
String
headPicture
;
@ApiModelProperty
(
value
=
"国籍"
)
private
String
nationality
;
@ApiModelProperty
(
value
=
"单位全称"
)
private
String
unitName
;
@ApiModelProperty
(
value
=
"微信OPENT_ID"
)
private
String
openId
;
@ApiModelProperty
(
value
=
"是否开启指纹登录 0 未开启 1 已开启"
)
private
String
figerprintFalg
;
@ApiModelProperty
(
value
=
"是否开启人脸识别登录 0 未开启 1 已开启"
)
private
String
faceidFalg
;
@ApiModelProperty
(
value
=
"创建时间"
)
private
Date
createTime
;
@ApiModelProperty
(
value
=
"更新时间"
)
private
Date
updateTime
;
@ApiModelProperty
(
value
=
"是否有效标识 0 有效用户 1无效用户"
)
private
String
isEnable
;
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment