Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fzm-joying
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
lei
fzm-joying
Commits
a557ec87
Commit
a557ec87
authored
Jul 19, 2021
by
tangtuo
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev_1.0.0' into test_v1.0.0
parents
ec934149
3a0a4f59
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
40 additions
and
10 deletions
+40
-10
InterceptorConfig.java
...rc/main/java/com/fzm/common/config/InterceptorConfig.java
+2
-1
NftVo.java
...-common/src/main/java/com/fzm/common/entity/vo/NftVo.java
+4
-0
AuthenticationInterceptor.java
...com/fzm/common/interceptor/AuthenticationInterceptor.java
+6
-2
UserServiceImpl.java
...ain/java/com/fzm/common/service/impl/UserServiceImpl.java
+1
-1
JwtUtil.java
...ng-common/src/main/java/com/fzm/common/utils/JwtUtil.java
+4
-3
OssUtil.java
...ng-common/src/main/java/com/fzm/common/utils/OssUtil.java
+1
-0
NftController.java
...rc/main/java/com/fzm/portal/controller/NftController.java
+11
-1
UserController.java
...c/main/java/com/fzm/portal/controller/UserController.java
+9
-0
LyPortalApplicationTests.java
...rc/test/java/com/fzm/portal/LyPortalApplicationTests.java
+2
-2
No files found.
joying-common/src/main/java/com/fzm/common/config/InterceptorConfig.java
View file @
a557ec87
...
...
@@ -12,7 +12,8 @@ public class InterceptorConfig implements WebMvcConfigurer {
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
authenticationInterceptor
())
.
addPathPatterns
(
"/**"
);
// 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录
.
excludePathPatterns
(
"/user/login"
,
"/admin/login"
,
"/verificationCode/send/sms"
)
.
addPathPatterns
(
"/**"
);
}
@Bean
public
AuthenticationInterceptor
authenticationInterceptor
()
{
...
...
joying-common/src/main/java/com/fzm/common/entity/vo/NftVo.java
View file @
a557ec87
...
...
@@ -56,6 +56,9 @@ public class NftVo {
@ApiModelProperty
(
"授权阅读 0-不需要授权 1-需要授权"
)
private
Integer
isGrant
;
@ApiModelProperty
(
"是否收藏"
)
private
Boolean
collection
;
@ApiModelProperty
(
"关于nft"
)
private
String
aboutNft
;
...
...
@@ -73,5 +76,6 @@ public class NftVo {
this
.
publishTime
=
DateUtil
.
format
(
nft
.
getPublishTime
(),
"yyyy/MM/dd HH:mm:ss"
);
this
.
isArchives
=
nft
.
getIsArchives
();
this
.
isGrant
=
nft
.
getIsGrant
();
this
.
collection
=
false
;
}
}
joying-common/src/main/java/com/fzm/common/interceptor/AuthenticationInterceptor.java
View file @
a557ec87
...
...
@@ -56,10 +56,13 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
if
(!
token
.
startsWith
(
TokenConstant
.
TOKEN_PREFIX
))
{
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
"非法token"
);
}
String
realToken
=
token
.
substring
(
TokenConstant
.
TOKEN_PREFIX
.
length
());
if
(
StringUtils
.
isBlank
(
realToken
)
||
"null"
.
equals
(
realToken
))
{
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
"请先登录"
);
}
if
(
JwtUtil
.
isTokenExpired
(
token
))
{
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
"登录已过期"
);
}
String
realToken
=
token
.
substring
(
TokenConstant
.
TOKEN_PREFIX
.
length
());
String
appId
=
JwtUtil
.
getAppIdFromToken
(
token
);
Integer
userId
=
JwtUtil
.
getUserIdFromToken
(
token
);
AbstractUser
user
;
...
...
@@ -109,7 +112,8 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
}
public
static
void
main
(
String
[]
args
)
{
String
token
=
"Bearer
token121323433
"
;
String
token
=
"Bearer
null
"
;
System
.
out
.
println
(
token
.
substring
(
"Bearer "
.
length
()));
System
.
out
.
println
(
StringUtils
.
isBlank
(
token
.
substring
(
"Bearer "
.
length
())));
}
}
joying-common/src/main/java/com/fzm/common/service/impl/UserServiceImpl.java
View file @
a557ec87
...
...
@@ -140,7 +140,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
case
"voice"
:
return
smsProperties
.
getVoiceLoginCodetype
();
default
:
throw
GlobalException
.
newException
(
ResultCode
.
CODE_ERROR
);
throw
GlobalException
.
newException
(
ResultCode
.
VALIDATE_FAILED
,
"短信类型【"
+
type
+
"】的传参有误,取值范围是{sms,email,voice}"
);
}
}
...
...
joying-common/src/main/java/com/fzm/common/utils/JwtUtil.java
View file @
a557ec87
...
...
@@ -55,6 +55,7 @@ public class JwtUtil {
.
getBody
();
}
catch
(
Exception
e
)
{
log
.
info
(
"JWT格式验证失败:{}"
,
token
);
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
e
.
getMessage
());
}
return
claims
;
}
...
...
@@ -80,7 +81,7 @@ public class JwtUtil {
Claims
claims
=
getClaimsFromToken
(
token
);
return
claims
.
get
(
CLAIM_KEY_CREATED
,
Date
.
class
);
}
catch
(
Exception
e
)
{
throw
GlobalException
.
newException
(
ResultCode
.
TOKEN_VALID_ERROR
,
e
.
getMessage
());
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
e
.
getMessage
());
}
}
...
...
@@ -92,7 +93,7 @@ public class JwtUtil {
Claims
claims
=
getClaimsFromToken
(
token
);
return
claims
.
get
(
CLAIM_KEY_USERID
,
Integer
.
class
);
}
catch
(
Exception
e
)
{
throw
GlobalException
.
newException
(
ResultCode
.
TOKEN_VALID_ERROR
,
e
.
getMessage
());
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
e
.
getMessage
());
}
}
...
...
@@ -104,7 +105,7 @@ public class JwtUtil {
Claims
claims
=
getClaimsFromToken
(
token
);
return
claims
.
get
(
CLAIM_KEY_APP_ID
,
String
.
class
);
}
catch
(
Exception
e
)
{
throw
GlobalException
.
newException
(
ResultCode
.
TOKEN_VALID_ERROR
,
e
.
getMessage
());
throw
GlobalException
.
newException
(
ResultCode
.
UNAUTHORIZED
,
e
.
getMessage
());
}
}
...
...
joying-common/src/main/java/com/fzm/common/utils/OssUtil.java
View file @
a557ec87
...
...
@@ -142,6 +142,7 @@ public class OssUtil {
if
(
in
!=
null
)
{
in
.
close
();
}
ossClient
.
shutdown
();
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
GlobalException
.
newException
(
ResultCode
.
FILE_DOWNLOAD_ERROR
,
e
.
getMessage
());
...
...
joying-portal/src/main/java/com/fzm/portal/controller/NftController.java
View file @
a557ec87
...
...
@@ -2,6 +2,7 @@ package com.fzm.portal.controller;
import
cn.hutool.crypto.SecureUtil
;
import
com.fzm.common.annotation.Authentication
;
import
com.fzm.common.constant.RedisConstant
;
import
com.fzm.common.constant.SystemConstant
;
import
com.fzm.common.entity.Nft
;
import
com.fzm.common.entity.NftDto
;
...
...
@@ -18,6 +19,7 @@ import com.fzm.common.service.UserService;
import
com.fzm.common.utils.JwtUtil
;
import
com.fzm.common.utils.OssUtil
;
import
com.fzm.common.utils.QRCodeUtil
;
import
com.fzm.common.utils.RedisUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
...
...
@@ -58,6 +60,9 @@ public class NftController {
private
CategoryService
categoryService
;
@Resource
private
RedisUtil
redisUtil
;
@Resource
private
HttpServletRequest
request
;
/**
...
...
@@ -101,7 +106,7 @@ public class NftController {
@GetMapping
(
"get/{id}"
)
@ApiOperation
(
value
=
"获取nft详情"
)
public
ResponseModel
<
NftVo
>
getById
(
@PathVariable
Integer
id
)
{
public
ResponseModel
<
NftVo
>
getById
(
@PathVariable
Integer
id
,
@RequestHeader
(
required
=
false
)
String
Authorization
)
{
Nft
nft
=
nftService
.
getById
(
id
);
if
(
nft
==
null
)
{
throw
GlobalException
.
newException
(
ResultCode
.
DATA_ERROR
,
"没找到此nft的详情"
);
...
...
@@ -112,6 +117,11 @@ public class NftController {
}
NftVo
nftVo
=
new
NftVo
(
nft
,
user
);
nftVo
.
setCategory
(
categoryService
.
getById
(
nft
.
getCategoryId
()).
getCategoryName
());
if
(
StringUtils
.
isNotBlank
(
Authorization
))
{
Integer
userId
=
JwtUtil
.
getUserIdFromToken
(
Authorization
);
Boolean
collection
=
redisUtil
.
sIsMember
(
RedisConstant
.
COLLECTION_USER_PREFIX
+
userId
,
id
.
toString
());
nftVo
.
setCollection
(
collection
);
}
return
ResponseModel
.
success
(
nftVo
);
}
...
...
joying-portal/src/main/java/com/fzm/portal/controller/UserController.java
View file @
a557ec87
...
...
@@ -81,6 +81,15 @@ public class UserController {
return
ResponseModel
.
success
(
user
!=
null
&&
StringUtils
.
isNotBlank
(
user
.
getPassword
()));
}
@Authentication
@PostMapping
(
value
=
"/logout"
)
@ApiOperation
(
value
=
"判断用户是否已注册过"
)
public
ResponseModel
<
Boolean
>
logout
(
@RequestHeader
String
Authorization
)
{
Integer
userId
=
JwtUtil
.
getUserIdFromToken
(
Authorization
);
redisUtil
.
delete
(
RedisConstant
.
PORTAL_USER_TOKEN_PREFIX
+
userId
);
return
ResponseModel
.
success
();
}
//@ApiOperation(value = "设置密码")
public
ResponseModel
<
Boolean
>
setPassword
()
{
return
ResponseModel
.
success
();
...
...
joying-portal/src/test/java/com/fzm/portal/LyPortalApplicationTests.java
View file @
a557ec87
package
com
.
fzm
.
portal
;
import
cn.fzm.chain.simplesdk.client.ParaChainClient
;
import
com.fzm.common.constant.RedisConstant
;
import
com.fzm.common.utils.JsonUtil
;
import
com.fzm.common.utils.RedisUtil
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -29,8 +30,7 @@ class LyPortalApplicationTests {
@Test
void
contextLoads
()
{
System
.
out
.
println
(
redisUtil
.
setMembers
(
"user:collect:2"
));
System
.
out
.
println
(
redisUtil
.
sSize
(
"user:collect:2"
));
System
.
out
.
println
(
redisUtil
.
sIsMember
(
RedisConstant
.
COLLECTION_USER_PREFIX
+
9
,
"2"
));
}
}
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