Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
D
data-server
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
licc
data-server
Commits
5473549d
Commit
5473549d
authored
Mar 11, 2021
by
m1991
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录——新加退出功能
parent
5ba2c6f8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
284 additions
and
4 deletions
+284
-4
Constants.java
...on/src/main/java/cn/wisenergy/common/utils/Constants.java
+20
-0
RedisKeyUtils.java
...rc/main/java/cn/wisenergy/common/utils/RedisKeyUtils.java
+39
-0
wisenergy-model.iml
wisenergy-model/wisenergy-model.iml
+171
-0
UserService.java
...e/src/main/java/cn/wisenergy/service/app/UserService.java
+6
-0
UserServiceImpl.java
...n/java/cn/wisenergy/service/app/impl/UserServiceImpl.java
+19
-4
LoginController.java
...n/wisenergy/web/admin/controller/app/LoginController.java
+29
-0
No files found.
wisenergy-common/src/main/java/cn/wisenergy/common/utils/Constants.java
View file @
5473549d
...
...
@@ -85,4 +85,24 @@ public class Constants {
public
static
String
TOKEN_PRIFIX
=
"token"
;
public
static
String
BANK_PRIFIX
=
"bank"
;
}
/**
* redis常量
*/
public
static
class
Redis
{
/**
* 项目公共 前缀
*/
public
final
static
String
PREFIX
=
"xts"
;
/**
* 短信相关
*/
public
final
static
String
PREFIX_SMS
=
"sms:"
;
/**
* token相关
*/
public
final
static
String
PREFIX_TOKEN
=
"token:"
;
}
}
wisenergy-common/src/main/java/cn/wisenergy/common/utils/RedisKeyUtils.java
0 → 100644
View file @
5473549d
package
cn
.
wisenergy
.
common
.
utils
;
/**
* redis key工具类
* m1991
*/
public
class
RedisKeyUtils
{
/**
* 根据出入的参数创建一个Redis key
* @return 如果参数为空,那么返回null
*/
public
static
String
formatKeys
(
String
...
args
){
if
(
args
!=
null
&&
args
.
length
>
0
){
StringBuilder
key
=
new
StringBuilder
();
for
(
String
s:
args
){
key
.
append
(
s
).
append
(
Constants
.
Connnector
.
UNDERLINE
);
}
return
key
.
toString
();
}
return
null
;
}
/**
* 根据出入的参数创建一个Redis key,自动拼接前缀
* @return 如果参数为空,那么返回null
*/
public
static
String
formatKeyWithPrefix
(
String
...
args
){
if
(
args
!=
null
&&
args
.
length
>
0
){
StringBuilder
key
=
new
StringBuilder
(
Constants
.
Redis
.
PREFIX
).
append
(
Constants
.
Connnector
.
UNDERLINE
);
for
(
String
s:
args
){
key
.
append
(
s
).
append
(
Constants
.
Connnector
.
UNDERLINE
);
}
return
key
.
toString
();
}
return
null
;
}
}
\ No newline at end of file
wisenergy-model/wisenergy-model.iml
View file @
5473549d
This diff is collapsed.
Click to expand it.
wisenergy-service/src/main/java/cn/wisenergy/service/app/UserService.java
View file @
5473549d
...
...
@@ -47,6 +47,12 @@ public interface UserService {
*/
Map
userByZx
(
String
userId
,
String
beInvitedCode
);
/**
* 用户登出
* @param token
* @return
*/
int
logout
(
String
token
);
Integer
getUserIdById
(
String
userId
);
...
...
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/UserServiceImpl.java
View file @
5473549d
package
cn
.
wisenergy
.
service
.
app
.
impl
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.common.utils.RedisUtils
;
import
cn.wisenergy.common.utils.ResultUtils
;
import
cn.wisenergy.common.utils.ShareCodeUtil
;
import
cn.wisenergy.common.utils.*
;
import
cn.wisenergy.mapper.RecommendUserMapper
;
import
cn.wisenergy.mapper.TeamUserInfoMapper
;
import
cn.wisenergy.mapper.UsersMapper
;
...
...
@@ -42,6 +39,9 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
@Autowired
private
TeamUserInfoMapper
teamUserInfoMapper
;
@Autowired
private
RedisUtils
redisUtils
;
@Override
public
User
getById
(
String
userId
)
{
return
usersMapper
.
getByUserId
(
userId
);
...
...
@@ -284,4 +284,19 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
teamgg
(
beInvitedCode
);
return
R
.
ok
(
"团队表普通用户数量+1成功!"
,
0
);
}
/**
* 用户登出
* @param token
* @return
*/
@Override
public
int
logout
(
String
token
)
{
int
succ
=
0
;
String
key
=
RedisKeyUtils
.
formatKeyWithPrefix
(
token
);
redisUtils
.
delete
(
key
);
if
(
redisUtils
.
getValue
(
key
)
==
null
){
succ
=
1
;
}
return
succ
;
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/LoginController.java
View file @
5473549d
...
...
@@ -2,6 +2,7 @@ package cn.wisenergy.web.admin.controller.app;
import
cn.hutool.extra.qrcode.QrCodeUtil
;
import
cn.hutool.extra.qrcode.QrConfig
;
import
cn.wisenergy.common.enums.ResultEnum
;
import
cn.wisenergy.common.utils.*
;
import
cn.wisenergy.model.app.User
;
import
cn.wisenergy.model.app.UsersDto
;
...
...
@@ -43,6 +44,9 @@ import java.util.Map;
@RequestMapping
(
"api/user"
)
@RestController
public
class
LoginController
{
@Autowired
private
RedisUtils
redisUtils
;
...
...
@@ -183,4 +187,29 @@ public class LoginController {
return
usersService
.
userByZx
(
userId
,
beInvitedCode
);
}
/**
* 退出登录
* @param request
* @return
*/
@ApiOperation
(
value
=
"退出登录"
,
produces
=
"application/json"
,
notes
=
"退出登录"
)
@ApiImplicitParam
(
paramType
=
"header"
,
name
=
"token"
,
value
=
"用户token"
,
required
=
true
,
dataType
=
"String"
)
@PostMapping
(
"/logout"
)
public
Result
logout
(
HttpServletRequest
request
)
{
log
.
info
(
"退出登录"
);
Result
result
=
ResultUtils
.
returnFail
();
String
token
=
request
.
getHeader
(
"token"
);
String
key
=
RedisKeyUtils
.
formatKeyWithPrefix
(
Constants
.
Redis
.
PREFIX_TOKEN
,
token
);
if
(
redisUtils
.
getValue
(
key
)
==
null
){
log
.
info
(
"要退出登录的用户未登录"
);
return
ResultUtils
.
returnResult
(
ResultEnum
.
FILE_NOT_LOGIN
);
}
int
succ
=
usersService
.
logout
(
token
);
if
(
succ
>
0
)
{
result
=
ResultUtils
.
returnSuccess
();
}
return
result
;
}
}
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