Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
liyeyun-user-web
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
cfld-backend
liyeyun-user-web
Commits
b27fa251
Commit
b27fa251
authored
Nov 23, 2023
by
zhouxudong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新用户模块
parent
7dd6c4b8
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
370 additions
and
150 deletions
+370
-150
LyyUserApplication.java
src/main/java/com/lyy/user/LyyUserApplication.java
+4
-0
WebConfig.java
src/main/java/com/lyy/user/config/auth/WebConfig.java
+35
-10
GlobalResponseBodyAdvice.java
...a/com/lyy/user/config/other/GlobalResponseBodyAdvice.java
+1
-1
SwaggerConfig.java
src/main/java/com/lyy/user/config/swagger/SwaggerConfig.java
+74
-0
Constants.java
src/main/java/com/lyy/user/constant/Constants.java
+2
-0
BaseResult.java
src/main/java/com/lyy/user/domain/BaseResult.java
+6
-0
SendMsgTypeEnum.java
src/main/java/com/lyy/user/enums/SendMsgTypeEnum.java
+27
-24
SysPcLoginController.java
...yy/user/moudle/login/controller/SysPcLoginController.java
+22
-15
SysUserController.java
...om/lyy/user/moudle/user/controller/SysUserController.java
+20
-0
SysUserInfoService.java
.../com/lyy/user/moudle/user/service/SysUserInfoService.java
+8
-13
SysUserInfoServiceImpl.java
...user/moudle/user/service/impl/SysUserInfoServiceImpl.java
+62
-77
ForgetVo.java
src/main/java/com/lyy/user/moudle/user/vo/ForgetVo.java
+40
-0
LoginVo.java
src/main/java/com/lyy/user/moudle/user/vo/LoginVo.java
+15
-3
PhoneLoginVo.java
src/main/java/com/lyy/user/moudle/user/vo/PhoneLoginVo.java
+5
-0
RegisterVo.java
src/main/java/com/lyy/user/moudle/user/vo/RegisterVo.java
+16
-5
SendPhoneVo.java
src/main/java/com/lyy/user/moudle/user/vo/SendPhoneVo.java
+5
-0
RedisUtil.java
src/main/java/com/lyy/user/util/redis/RedisUtil.java
+13
-1
application-dev.yml
src/main/resources/application-dev.yml
+6
-0
application-pro.yml
src/main/resources/application-pro.yml
+4
-0
application-test.yml
src/main/resources/application-test.yml
+3
-0
application.yml
src/main/resources/application.yml
+2
-1
No files found.
src/main/java/com/lyy/user/LyyUserApplication.java
View file @
b27fa251
...
...
@@ -2,6 +2,8 @@ package com.lyy.user;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
springfox.documentation.oas.annotations.EnableOpenApi
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
/**
* @Author:zhouxudong
...
...
@@ -10,6 +12,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @Description:
*/
@SpringBootApplication
/*@EnableOpenApi
@EnableSwagger2*/
public
class
LyyUserApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
LyyUserApplication
.
class
,
args
);
...
...
src/main/java/com/lyy/user/config/auth/WebConfig.java
View file @
b27fa251
...
...
@@ -2,6 +2,7 @@ package com.lyy.user.config.auth;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
...
...
@@ -11,6 +12,7 @@ import java.util.Collections;
/** Web层配置类 */
@Configuration
@EnableWebMvc
public
class
WebConfig
implements
WebMvcConfigurer
{
@Override
...
...
@@ -22,19 +24,22 @@ public class WebConfig implements WebMvcConfigurer {
.
addPathPatterns
(
getIncludePathPatterns
())
.
excludePathPatterns
(
getExcludePathPatterns
());
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/**"
).
addResourceLocations
(
"classpath:/static/"
);
registry
.
addResourceHandler
(
"swagger-ui.html"
)
.
addResourceLocations
(
"classpath:/META-INF/resources/"
);
registry
.
addResourceHandler
(
"doc.html"
)
.
addResourceLocations
(
"classpath:/META-INF/resources/"
);
registry
.
addResourceHandler
(
"/webjars/**"
)
.
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
);
}
@Bean
CurrentUserInterceptor
getCurrentUserInterceptor
()
{
return
new
CurrentUserInterceptor
();
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/**"
)
.
addResourceLocations
(
"classpath:/template/"
)
.
addResourceLocations
(
"classpath:/templates/"
);
}
/** 需要拦截的信息 */
private
ArrayList
<
String
>
getIncludePathPatterns
()
{
...
...
@@ -47,8 +52,28 @@ public class WebConfig implements WebMvcConfigurer {
/** 不需要任何用户信息 白名单 */
private
ArrayList
<
String
>
getExcludePathPatterns
()
{
ArrayList
<
String
>
list
=
new
ArrayList
<>();
String
[]
urls
=
{
"/pc/**"
};
Collections
.
addAll
(
list
,
urls
);
list
.
add
(
"/pc/**"
);
String
[]
excludeSwagger
=
new
String
[]{
"/swagger-resources/**"
,
"/swagger-ui.html"
,
"/webjars/**"
,
"/v3/**"
,
"/v2/**"
,
"/swagger**/**"
,
"/swagger-ui/index.html"
,
"/swagger-ui/index.html/**"
,
"/doc.html"
,
"doc.html/**"
,
"/doc.html#/**"
,
"/**/login"
,
"/favicon.ico"
,
"/favicon.ico/**"
,
"/swagger-ui.html/**"
};
Collections
.
addAll
(
list
,
excludeSwagger
);
return
list
;
}
}
src/main/java/com/lyy/user/config/other/GlobalResponseBodyAdvice.java
View file @
b27fa251
...
...
@@ -22,7 +22,7 @@ import java.util.HashMap;
* @author chaus
* @date
*/
@RestControllerAdvice
@RestControllerAdvice
(
basePackages
=
"com.lyy.user.moudle"
)
@Slf4j
public
class
GlobalResponseBodyAdvice
implements
ResponseBodyAdvice
{
@Override
...
...
src/main/java/com/lyy/user/config/swagger/SwaggerConfig.java
0 → 100644
View file @
b27fa251
package
com
.
lyy
.
user
.
config
.
swagger
;
import
com.lyy.user.domain.BaseResult
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.*
;
import
springfox.documentation.service.*
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @Author:zhouxudong
*
* @version: 1.0 @Date: 2023/11/22 18:31 @Description:
*/
@Slf4j
@Configuration
public
class
SwaggerConfig
{
@Bean
// 相当于Spring 配置中的<bean>
public
Docket
createRestApi
()
{
/** 更改默认返回码 */
List
<
Response
>
responseList
=
new
ArrayList
<>();
responseList
.
add
(
new
ResponseBuilder
()
.
code
(
String
.
valueOf
(
BaseResult
.
SUCCESS
))
.
description
(
BaseResult
.
ok
().
getMessage
())
.
build
());
return
new
Docket
(
DocumentationType
.
OAS_30
)
/*.globalResponses(GET, responseList)
.globalResponses(POST, responseList)
.globalResponses(PUT, responseList)
.globalResponses(DELETE, responseList)*/
// 是否启用Swagger
//分组设置
.
groupName
(
"区域大纲基本接口"
)
// 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
.
apiInfo
(
apiInfo
())
// 设置哪些接口暴露给Swagger展示
.
select
()
// 扫描所有有注解的api,用这种方式更灵活
.
apis
(
RequestHandlerSelectors
.
withMethodAnnotation
(
ApiOperation
.
class
))
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
// 用ApiInfoBuilder进行定制
return
new
ApiInfoBuilder
()
// 设置标题
.
title
(
"标题:用户模块_接口文档"
)
// 描述
.
description
(
"描述:用户模块_接口文档"
)
// 作者信息
.
contact
(
new
Contact
(
"LYY"
,
null
,
null
))
// 版本
.
version
(
"版本号:v1.0"
)
.
build
();
}
}
src/main/java/com/lyy/user/constant/Constants.java
View file @
b27fa251
...
...
@@ -118,4 +118,6 @@ public class Constants {
public
static
final
String
MSG_KEY
=
"phone:message:"
;
public
static
final
String
TOKEN_HEADER
=
"Authorization"
;
//秒
public
static
final
int
INTERVAL_TIME
=
4
*
60
;
}
src/main/java/com/lyy/user/domain/BaseResult.java
View file @
b27fa251
package
com
.
lyy
.
user
.
domain
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
...
...
@@ -10,9 +12,13 @@ import lombok.ToString;
@NoArgsConstructor
@AllArgsConstructor
@ToString
@ApiModel
(
"响应参数"
)
public
class
BaseResult
<
T
>
{
@ApiModelProperty
(
"success标识,true表示成功,false表示失败"
)
private
boolean
success
;
// 状态说明:true 执行成功; false 发生异常
@ApiModelProperty
(
"响应信息"
)
private
String
message
;
// 异常说明
@ApiModelProperty
(
"响应数据"
)
private
T
data
;
// 业务数据
/** 成功 */
...
...
src/main/java/com/lyy/user/enums/SendMsgTypeEnum.java
View file @
b27fa251
...
...
@@ -4,33 +4,36 @@ import lombok.Getter;
@Getter
public
enum
SendMsgTypeEnum
{
REGISTER
(
1
,
"a0072fe0c74c47e59fbf700a4ce94350"
,
"注册"
),
LOGIN
(
2
,
"a0072fe0c74c47e59fbf700a4ce94350"
,
"登录"
);
private
final
Integer
code
;
REGISTER
(
1
,
"a0072fe0c74c47e59fbf700a4ce94350"
,
"注册"
),
LOGIN
(
2
,
"a0072fe0c74c47e59fbf700a4ce94350"
,
"登录"
),
FORGOT_PASSWORD
(
3
,
"a0072fe0c74c47e59fbf700a4ce94350"
,
"忘记密码"
),
UPDATE_PASSWORD
(
4
,
"a0072fe0c74c47e59fbf700a4ce94350"
,
"修改密码"
);
private
final
Integer
code
;
private
final
String
templateId
;
private
final
String
name
;
private
final
String
templateId
;
private
final
String
name
;
SendMsgTypeEnum
(
Integer
code
,
String
templateId
,
String
name
)
{
this
.
code
=
code
;
this
.
templateId
=
templateId
;
this
.
name
=
name
;
}
SendMsgTypeEnum
(
Integer
code
,
String
templateId
,
String
name
)
{
this
.
code
=
code
;
this
.
templateId
=
templateId
;
this
.
name
=
name
;
}
public
static
String
getTemplateId
(
Integer
code
){
for
(
SendMsgTypeEnum
bt:
values
()){
if
(
bt
.
code
.
equals
(
code
)){
return
bt
.
templateId
;
}
}
return
null
;
public
static
String
getTemplateId
(
Integer
code
)
{
for
(
SendMsgTypeEnum
bt
:
values
())
{
if
(
bt
.
code
.
equals
(
code
))
{
return
bt
.
templateId
;
}
}
public
static
String
getName
(
Integer
code
){
for
(
SendMsgTypeEnum
bt:
values
()){
if
(
bt
.
code
.
equals
(
code
)){
return
bt
.
templateId
;
}
}
return
null
;
return
null
;
}
public
static
String
getName
(
Integer
code
)
{
for
(
SendMsgTypeEnum
bt
:
values
())
{
if
(
bt
.
code
.
equals
(
code
))
{
return
bt
.
templateId
;
}
}
return
null
;
}
}
src/main/java/com/lyy/user/moudle/login/controller/SysPcLoginController.java
View file @
b27fa251
package
com
.
lyy
.
user
.
moudle
.
login
.
controller
;
import
com.lyy.user.enums.SendMsgTypeEnum
;
import
com.lyy.user.moudle.user.service.SysUserInfoService
;
import
com.lyy.user.moudle.user.vo.LoginVo
;
import
com.lyy.user.moudle.user.vo.PhoneLoginVo
;
import
com.lyy.user.moudle.user.vo.RegisterVo
;
import
com.lyy.user.moudle.user.vo.SendPhoneVo
;
import
com.lyy.user.moudle.user.vo.*
;
import
io.swagger.annotations.*
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -17,8 +16,9 @@ import javax.servlet.http.HttpServletRequest;
* @version: 1.0 @Date: 2023/11/16 14:09 @Description:pc登录
*/
@RestController
@RequestMapping
(
"/pc"
)
@RequestMapping
(
"/pc
/v1.0
"
)
@RequiredArgsConstructor
@Api
(
tags
=
"登录模块"
)
public
class
SysPcLoginController
{
private
final
SysUserInfoService
sysUserInfoService
;
...
...
@@ -29,6 +29,7 @@ public class SysPcLoginController {
* @return: java.lang.String
*/
@PostMapping
(
"/login"
)
@ApiOperation
(
value
=
"密码登录"
)
public
String
login
(
@Validated
@RequestBody
LoginVo
loginVo
)
{
return
this
.
sysUserInfoService
.
loginPc
(
loginVo
);
...
...
@@ -42,6 +43,7 @@ public class SysPcLoginController {
*/
// 测试手机格式
@PostMapping
(
"/phoneLogin"
)
@ApiOperation
(
value
=
"手机号登录"
,
notes
=
"手机号登录"
)
public
String
phoneLogin
(
@Validated
@RequestBody
PhoneLoginVo
phoneLoginVo
)
{
return
sysUserInfoService
.
phoneLogin
(
phoneLoginVo
);
}
...
...
@@ -53,6 +55,8 @@ public class SysPcLoginController {
* @return: boolean
*/
@GetMapping
(
"/check/{phone}"
)
@ApiOperation
(
value
=
"核对手机号是否已经注册"
,
notes
=
"核对手机号是否已经注册"
)
@ApiImplicitParam
(
name
=
"phone"
,
value
=
"手机号"
)
public
boolean
checkPhone
(
@PathVariable
(
"phone"
)
String
phone
)
{
return
this
.
sysUserInfoService
.
checkPhone
(
phone
);
}
...
...
@@ -63,19 +67,10 @@ public class SysPcLoginController {
* @return: boolean
*/
@PostMapping
(
"/sendMsg"
)
@ApiOperation
(
value
=
"发送短信"
,
notes
=
"发送短信"
)
public
boolean
sendMsg
(
@RequestBody
@Validated
SendPhoneVo
sendPhoneVo
)
{
return
this
.
sysUserInfoService
.
sendMsg
(
sendPhoneVo
);
}
/**
* @description: 发送短信
* @date: 2023/11/20 14:21
* @param: [phone]
* @return: boolean
*/
@PostMapping
(
"/sendMsg/{phone}"
)
public
boolean
sendMsg
(
@PathVariable
(
"phone"
)
String
phone
)
{
return
this
.
sysUserInfoService
.
sendMsg
(
phone
);
}
/**
* @description: 注册
...
...
@@ -84,7 +79,19 @@ public class SysPcLoginController {
* @return: boolean
*/
@PostMapping
(
"/sign"
)
@ApiOperation
(
value
=
"注册"
)
public
boolean
sign
(
@RequestBody
@Validated
RegisterVo
registerVo
)
{
return
this
.
sysUserInfoService
.
sign
(
registerVo
);
}
/**
* @description: 忘记密码
* @date: 2023/11/23 10:20
* @param: [forgetVo]
* @return: boolean
*/
@PostMapping
(
"/forget"
)
@ApiOperation
(
value
=
"忘记密码"
)
public
boolean
forget
(
@RequestBody
@Validated
ForgetVo
forgetVo
)
{
return
this
.
sysUserInfoService
.
forget
(
forgetVo
,
SendMsgTypeEnum
.
FORGOT_PASSWORD
.
getCode
());
}
}
src/main/java/com/lyy/user/moudle/user/controller/SysUserController.java
View file @
b27fa251
...
...
@@ -4,10 +4,16 @@ import com.lyy.user.config.auth.CurrentUserInterceptor;
import
com.lyy.user.config.other.BaseContextHandler
;
import
com.lyy.user.constant.Constants
;
import
com.lyy.user.domain.JwtInfo
;
import
com.lyy.user.enums.SendMsgTypeEnum
;
import
com.lyy.user.moudle.user.service.SysUserInfoService
;
import
com.lyy.user.moudle.user.vo.ForgetVo
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.tomcat.util.bcel.Const
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -21,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping
(
"/user"
)
@RequiredArgsConstructor
@Api
(
tags
=
"用户模块 需要认证 请求头传参数(值为token):Authorization"
)
public
class
SysUserController
{
private
final
SysUserInfoService
sysUserInfoService
;
...
...
@@ -31,7 +38,20 @@ public class SysUserController {
* @return: boolean
*/
@PostMapping
(
"/logout"
)
@ApiOperation
(
value
=
"退出登录"
)
public
boolean
logout
(
HttpServletRequest
request
)
{
return
this
.
sysUserInfoService
.
logout
(
request
.
getHeader
(
Constants
.
TOKEN_HEADER
));
}
/**
* @description: 修改密码
* @date: 2023/11/23 10:20
* @param: [forgetVo]
* @return: boolean
*/
@PostMapping
(
"/update"
)
@ApiOperation
(
value
=
"修改密码"
)
public
boolean
update
(
@RequestBody
@Validated
ForgetVo
forgetVo
)
{
return
this
.
sysUserInfoService
.
forget
(
forgetVo
,
SendMsgTypeEnum
.
UPDATE_PASSWORD
.
getCode
());
}
}
src/main/java/com/lyy/user/moudle/user/service/SysUserInfoService.java
View file @
b27fa251
...
...
@@ -2,10 +2,7 @@ package com.lyy.user.moudle.user.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.lyy.user.moudle.user.entity.SysUserInfo
;
import
com.lyy.user.moudle.user.vo.LoginVo
;
import
com.lyy.user.moudle.user.vo.PhoneLoginVo
;
import
com.lyy.user.moudle.user.vo.RegisterVo
;
import
com.lyy.user.moudle.user.vo.SendPhoneVo
;
import
com.lyy.user.moudle.user.vo.*
;
/**
* @author 26996
...
...
@@ -14,9 +11,6 @@ import com.lyy.user.moudle.user.vo.SendPhoneVo;
*/
public
interface
SysUserInfoService
extends
IService
<
SysUserInfo
>
{
public
String
login
(
String
username
,
String
password
,
Integer
type
)
throws
Exception
;
public
void
resetPassword
(
Integer
userId
,
String
password
);
/**
* @description: pc端登录
...
...
@@ -53,13 +47,14 @@ public interface SysUserInfoService extends IService<SysUserInfo> {
* @return: boolean
**/
boolean
sendMsg
(
SendPhoneVo
sendPhoneVo
);
//用户注册
boolean
sign
(
RegisterVo
registerVo
);
/**
* @description:
发送短信
* @date: 2023/11/
16 18:36
* @param: [
phone
]
* @description:
忘记/修改密码
* @date: 2023/11/
23 10:21
* @param: [
forgetVo
]
* @return: boolean
**/
boolean
sendMsg
(
String
phone
);
//用户注册
boolean
sign
(
RegisterVo
registerVo
);
boolean
forget
(
ForgetVo
forgetVo
,
Integer
code
);
}
src/main/java/com/lyy/user/moudle/user/service/impl/SysUserInfoServiceImpl.java
View file @
b27fa251
...
...
@@ -21,6 +21,7 @@ import com.lyy.user.moudle.user.mapper.SysUserInfoMapper;
import
com.lyy.user.moudle.user.service.SysUserInfoService
;
import
com.lyy.user.moudle.user.vo.*
;
import
com.lyy.user.util.jwt.JwtTokenUtil
;
import
com.lyy.user.util.redis.RedisUtil
;
import
com.lyy.user.util.sms.SendMsgUtils
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -57,28 +58,6 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
@Autowired
private
SendMsgUtils
sendMsgUtils
;
@Override
public
String
login
(
String
loginName
,
String
password
,
Integer
type
)
{
// 判断当前用户是否存在
QueryWrapper
<
SysUserInfo
>
sysUserInfoQW
=
new
QueryWrapper
<>();
sysUserInfoQW
.
eq
(
"login_name"
,
loginName
);
SysUserInfo
sysUserInfo
=
this
.
getOne
(
sysUserInfoQW
);
if
(
sysUserInfo
==
null
)
{
throw
new
ServiceException
(
"当前用户不存在"
);
}
// 验证失败
if
(!
checkPassword
(
sysUserInfo
.
getPassword
(),
password
))
{
throw
new
ServiceException
(
"当前用户密码输入错误"
);
}
// 设置token
// String token = getToken(sysUserInfo, type);
String
token
=
JwtTokenUtil
.
createToken
(
sysUserInfo
,
null
);
stringRedisTemplate
.
opsForValue
()
.
set
(
Constants
.
token
+
token
,
sysUserInfo
.
getUserId
().
toString
(),
15
,
TimeUnit
.
DAYS
);
return
token
;
}
public
boolean
checkPassword
(
String
realPassword
,
String
password
)
{
String
md5Password
=
DigestUtils
.
md5DigestAsHex
((
password
+
lyyConfig
.
getPasswordSalt
()).
getBytes
());
...
...
@@ -102,7 +81,21 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
*/
@Override
public
String
loginPc
(
LoginVo
loginVo
)
{
return
login
(
loginVo
.
getUserName
(),
loginVo
.
getPassWord
(),
1
);
LambdaQueryWrapper
<
SysUserInfo
>
userQuery
=
new
LambdaQueryWrapper
<>();
userQuery
.
eq
(
SysUserInfo:
:
getPhonenumber
,
loginVo
.
getPhone
());
SysUserInfo
sysUserInfo
=
this
.
getOne
(
userQuery
);
if
(
ObjectUtils
.
isEmpty
(
sysUserInfo
))
{
throw
new
ServiceException
(
"当前用户不存在"
);
}
if
(
ObjectUtils
.
isEmpty
(
sysUserInfo
.
getPassword
()))
{
throw
new
ServiceException
(
"该用户密码不存在,请用短信验证码登录"
);
}
if
(!
checkPassword
(
sysUserInfo
.
getPassword
(),
loginVo
.
getPassword
()))
{
throw
new
ServiceException
(
"当前用户密码输入错误"
);
}
String
token
=
JwtTokenUtil
.
createToken
(
sysUserInfo
,
null
);
RedisUtil
.
set
(
Constants
.
token
+
token
,
sysUserInfo
.
getUserId
(),
15
,
TimeUnit
.
DAYS
);
return
token
;
}
/**
...
...
@@ -121,8 +114,8 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
}
String
phone
=
phoneLoginVo
.
getPhone
();
String
code
=
phoneLoginVo
.
getCode
();
String
msgCode
=
getPhoneKey
(
phone
,
SendMsgTypeEnum
.
LOGIN
.
getCode
());
if
(
StringUtils
.
isBlank
(
msgCode
))
{
Object
msgCode
=
getPhoneKey
(
phone
,
SendMsgTypeEnum
.
LOGIN
.
getCode
());
if
(
ObjectUtils
.
isEmpty
(
msgCode
))
{
throw
new
ServiceException
(
"验证码失效,请重新发送"
);
}
if
(!
code
.
equals
(
msgCode
))
{
...
...
@@ -137,10 +130,8 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
* @param: [phone, type]
* @return: java.lang.String
*/
private
String
getPhoneKey
(
String
phone
,
Integer
type
)
{
return
stringRedisTemplate
.
opsForValue
()
.
get
(
Constants
.
MSG_KEY
+
phone
);
private
Object
getPhoneKey
(
String
phone
,
Integer
type
)
{
return
RedisUtil
.
get
(
Constants
.
MSG_KEY
+
type
+
":"
+
phone
);
}
/**
* @description: 退出
...
...
@@ -167,38 +158,6 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
return
this
.
count
(
lambdaQueryWrapper
)
>
0
;
}
@Override
public
boolean
sendMsg
(
String
phone
)
{
check
(
phone
);
String
key
=
Constants
.
MSG_KEY
+
phone
;
String
code
=
stringRedisTemplate
.
opsForValue
().
get
(
key
);
if
(
StringUtils
.
isNotBlank
(
code
))
{
throw
new
ServiceException
(
"短信以发送,请勿重复发送"
);
}
int
randomInt
=
RandomUtil
.
randomInt
(
100000
,
999999
);
List
<
Integer
>
temp
=
new
ArrayList
<>();
temp
.
add
(
randomInt
);
// 发送短信
String
result
=
sendMsgUtils
.
sendMsg
(
phone
,
SendMsgTypeEnum
.
getTemplateId
(
1
),
temp
.
toString
());
log
.
info
(
"发送短信信息:{},返回结果:{}"
,
randomInt
,
result
);
if
(
ObjectUtils
.
isEmpty
(
result
))
{
throw
new
ServiceException
(
"短信发送失败"
);
}
SmsVo
smsVo
=
JSONUtil
.
toBean
(
result
,
SmsVo
.
class
);
SysSmsLogEntity
sysSmsLog
=
new
SysSmsLogEntity
();
sysSmsLog
.
setCode
(
smsVo
.
getCode
())
.
setDescription
(
smsVo
.
getDescription
())
.
setType
(
"登录/注册"
)
.
setResult
(
result
)
.
setPhone
(
phone
);
this
.
sysSmsLogService
.
save
(
sysSmsLog
);
if
(!
"000000"
.
equals
(
smsVo
.
getCode
()))
{
throw
new
ServiceException
(
"短信发送失败,请稍后重试"
);
}
stringRedisTemplate
.
opsForValue
().
set
(
key
,
String
.
valueOf
(
randomInt
),
5
,
TimeUnit
.
MINUTES
);
return
true
;
}
/**
* @description: 发送短信
* @date: 2023/11/16 18:36
...
...
@@ -212,9 +171,12 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
throw
new
ServiceException
(
"参数有误"
);
}
String
key
=
Constants
.
MSG_KEY
+
sendPhoneVo
.
getType
()
+
":"
+
sendPhoneVo
.
getPhone
();
String
code
=
stringRedisTemplate
.
opsForValue
().
get
(
key
);
if
(
StringUtils
.
isNotBlank
(
code
))
{
throw
new
ServiceException
(
"短信以发送,请勿重复发送"
);
Object
code
=
RedisUtil
.
get
(
key
);
//
Long
expire
=
RedisUtil
.
getExpire
(
key
);
// 间隔 1分钟内
if
(
expire
!=
null
&&
expire
>
Constants
.
INTERVAL_TIME
)
{
throw
new
ServiceException
(
"短信以发送,请稍后再发"
);
}
int
randomInt
=
RandomUtil
.
randomInt
(
100000
,
999999
);
List
<
Integer
>
temp
=
new
ArrayList
<>();
...
...
@@ -241,7 +203,7 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
if
(!
"000000"
.
equals
(
smsVo
.
getCode
()))
{
throw
new
ServiceException
(
"短信发送失败,请稍后重试"
);
}
stringRedisTemplate
.
opsForValue
()
.
set
(
key
,
String
.
valueOf
(
randomInt
),
5
,
TimeUnit
.
MINUTES
);
RedisUtil
.
set
(
key
,
String
.
valueOf
(
randomInt
),
5
,
TimeUnit
.
MINUTES
);
return
true
;
}
...
...
@@ -258,32 +220,55 @@ public class SysUserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUs
if
(
checkPhone
(
phone
))
{
throw
new
ServiceException
(
"手机号已经注册"
);
}
String
code
=
getPhoneKey
(
phone
,
SendMsgTypeEnum
.
REGISTER
.
getCode
());
if
(
StringUtils
.
isBlank
(
code
))
{
if
(!
registerVo
.
getPassword
().
equals
(
registerVo
.
getCheckPassword
()))
{
throw
new
ServiceException
(
"密码不一致,请重新填写"
);
}
Object
code
=
getPhoneKey
(
phone
,
SendMsgTypeEnum
.
REGISTER
.
getCode
());
if
(
ObjectUtils
.
isEmpty
(
code
))
{
throw
new
ServiceException
(
"验证码已失效"
);
}
if
(!
registerVo
.
getCode
().
equals
(
code
))
{
throw
new
ServiceException
(
"验证码有误"
);
}
String
userName
=
registerVo
.
getUserName
();
LambdaQueryWrapper
<
SysUserInfo
>
userLambdaQuery
=
new
LambdaQueryWrapper
<>();
userLambdaQuery
.
eq
(
SysUserInfo:
:
getLoginName
,
userName
);
long
count
=
this
.
count
(
userLambdaQuery
);
if
(
count
>
0
)
{
throw
new
ServiceException
(
"用户名重复"
);
}
SysUserInfo
userInfo
=
new
SysUserInfo
();
userInfo
.
setLoginName
(
registerVo
.
getUserName
()
);
userInfo
.
setUserName
(
registerVo
.
getUserName
()
);
userInfo
.
setLoginName
(
phone
);
userInfo
.
setUserName
(
phone
);
userInfo
.
setUserType
(
"00"
);
userInfo
.
setPhonenumber
(
phone
);
userInfo
.
setSex
(
"0"
);
userInfo
.
setPassword
(
DigestUtils
.
md5DigestAsHex
(
(
registerVo
.
getPass
W
ord
()
+
lyyConfig
.
getPasswordSalt
()).
getBytes
()));
(
registerVo
.
getPass
w
ord
()
+
lyyConfig
.
getPasswordSalt
()).
getBytes
()));
userInfo
.
setSalt
(
lyyConfig
.
getPasswordSalt
());
return
this
.
save
(
userInfo
);
}
/**
* @description: 忘记/修改密码
* @date: 2023/11/23 10:21
* @param: [forgetVo]
* @return: boolean
**/
@Override
public
boolean
forget
(
ForgetVo
forgetVo
,
Integer
type
)
{
String
phone
=
forgetVo
.
getPhone
();
LambdaQueryWrapper
<
SysUserInfo
>
userQuery
=
new
LambdaQueryWrapper
<>();
userQuery
.
eq
(
SysUserInfo:
:
getPhonenumber
,
phone
);
SysUserInfo
sysUserInfo
=
this
.
getOne
(
userQuery
);
if
(
ObjectUtils
.
isEmpty
(
sysUserInfo
)){
throw
new
ServiceException
(
"该用户不存在,请先注册"
);
}
String
key
=
Constants
.
MSG_KEY
+
type
+
":"
+
forgetVo
.
getPhone
();
Object
code
=
RedisUtil
.
get
(
key
);
if
(
ObjectUtils
.
isEmpty
(
code
)){
throw
new
ServiceException
(
"验证码无效,请重新发送"
);
}
if
(!
code
.
equals
(
forgetVo
.
getCode
())){
throw
new
ServiceException
(
"验证码错误"
);
}
String
newPassword
=
DigestUtils
.
md5DigestAsHex
((
forgetVo
.
getPassword
()
+
lyyConfig
.
getPasswordSalt
()).
getBytes
());
sysUserInfo
.
setPassword
(
newPassword
);
return
this
.
updateById
(
sysUserInfo
);
}
private
void
check
(
String
phone
)
{
if
(
StringUtils
.
isEmpty
(
phone
))
{
...
...
src/main/java/com/lyy/user/moudle/user/vo/ForgetVo.java
0 → 100644
View file @
b27fa251
package
com
.
lyy
.
user
.
moudle
.
user
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
org.hibernate.validator.constraints.NotEmpty
;
import
javax.validation.constraints.Pattern
;
import
javax.validation.constraints.Size
;
/**
* @Author:zhouxudong
* @version: 1.0
* @Date: 2023/11/17 9:38
* @Description: 忘记密码
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@ApiModel
(
value
=
"忘记/修改密码"
)
public
class
ForgetVo
{
@NotEmpty
(
message
=
"密码不能为空"
)
@Size
(
min
=
6
,
max
=
12
,
message
=
"密码长度需要在6到12之间"
)
@Pattern
(
regexp
=
"^[a-zA-Z0-9_]{6,12}$"
,
message
=
"密码只能包含字母和数字"
)
@ApiModelProperty
(
value
=
"密码"
,
required
=
true
)
private
String
password
;
@NotEmpty
(
message
=
"手机号不能为空"
)
@Pattern
(
regexp
=
"^1[3456789]\\d{9}$"
,
message
=
"手机号格式不正确"
)
@ApiModelProperty
(
value
=
"手机号"
,
required
=
true
)
private
String
phone
;
@NotEmpty
(
message
=
"验证码不能为空"
)
@ApiModelProperty
(
value
=
"验证码"
,
required
=
true
)
private
String
code
;
}
src/main/java/com/lyy/user/moudle/user/vo/LoginVo.java
View file @
b27fa251
package
com
.
lyy
.
user
.
moudle
.
user
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.hibernate.validator.constraints.NotBlank
;
import
org.hibernate.validator.constraints.NotEmpty
;
import
javax.validation.constraints.Pattern
;
import
javax.validation.constraints.Size
;
/**
* @Author:zhouxudong
...
...
@@ -19,11 +25,17 @@ import org.hibernate.validator.constraints.NotEmpty;
@AllArgsConstructor
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@ApiModel
(
value
=
"用户密码登录"
)
public
class
LoginVo
{
@NotEmpty
(
message
=
"用户名不能为空"
)
private
String
userName
;
@NotBlank
(
message
=
"手机号不能为空"
)
@Pattern
(
regexp
=
"^1[3456789]\\d{9}$"
,
message
=
"手机号格式不正确"
)
@ApiModelProperty
(
value
=
"手机号"
,
required
=
true
)
private
String
phone
;
@NotEmpty
(
message
=
"密码不能为空"
)
private
String
passWord
;
@Size
(
min
=
6
,
max
=
12
,
message
=
"密码长度需要在6到12之间"
)
@Pattern
(
regexp
=
"^[a-zA-Z0-9_]{6,12}$"
,
message
=
"密码只能包含字母和数字"
)
@ApiModelProperty
(
value
=
"密码"
,
required
=
true
)
private
String
password
;
}
src/main/java/com/lyy/user/moudle/user/vo/PhoneLoginVo.java
View file @
b27fa251
package
com
.
lyy
.
user
.
moudle
.
user
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
lombok.experimental.Accessors
;
import
org.hibernate.validator.constraints.NotBlank
;
...
...
@@ -19,10 +21,13 @@ import javax.validation.constraints.Pattern;
@ToString
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@ApiModel
(
value
=
"手机号登录"
)
public
class
PhoneLoginVo
{
@NotBlank
(
message
=
"手机号不能为空"
)
@Pattern
(
regexp
=
"^1[3456789]\\d{9}$"
,
message
=
"手机号格式不正确"
)
@ApiModelProperty
(
value
=
"手机号"
,
required
=
true
)
private
String
phone
;
@NotEmpty
(
message
=
"验证码不能为空"
)
@ApiModelProperty
(
value
=
"验证码"
,
required
=
true
)
private
String
code
;
}
src/main/java/com/lyy/user/moudle/user/vo/RegisterVo.java
View file @
b27fa251
package
com
.
lyy
.
user
.
moudle
.
user
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
org.hibernate.validator.constraints.NotEmpty
;
...
...
@@ -17,16 +19,25 @@ import javax.validation.constraints.Size;
@AllArgsConstructor
@NoArgsConstructor
@ToString
@ApiModel
(
value
=
"注册"
)
public
class
RegisterVo
{
@NotEmpty
(
message
=
"用户名不能为空"
)
@Size
(
min
=
6
,
max
=
12
,
message
=
"用户名长度需要在6到12之间"
)
@Pattern
(
regexp
=
"^[a-zA-Z0-9_]{6,12}$"
,
message
=
"用户名只能包含字母和数字"
)
private
String
userName
;
@NotEmpty
(
message
=
"密码不能为空"
)
private
String
passWord
;
@Size
(
min
=
6
,
max
=
12
,
message
=
"密码长度需要在6到12之间"
)
@Pattern
(
regexp
=
"^[a-zA-Z0-9_]{6,12}$"
,
message
=
"密码只能包含字母和数字"
)
@ApiModelProperty
(
value
=
"密码"
,
required
=
true
)
private
String
password
;
@NotEmpty
(
message
=
"手机号不能为空"
)
@Pattern
(
regexp
=
"^1[3456789]\\d{9}$"
,
message
=
"手机号格式不正确"
)
@ApiModelProperty
(
value
=
"手机号"
,
required
=
true
)
private
String
phone
;
@NotEmpty
(
message
=
"验证码不能为空"
)
@ApiModelProperty
(
value
=
"验证码"
,
required
=
true
)
private
String
code
;
@NotEmpty
(
message
=
"密码不能为空"
)
@Size
(
min
=
6
,
max
=
12
,
message
=
"密码长度需要在6到12之间"
)
@Pattern
(
regexp
=
"^[a-zA-Z0-9_]{6,12}$"
,
message
=
"密码只能包含字母和数字"
)
@ApiModelProperty
(
value
=
"确认密码"
,
required
=
true
)
private
String
checkPassword
;
}
src/main/java/com/lyy/user/moudle/user/vo/SendPhoneVo.java
View file @
b27fa251
package
com
.
lyy
.
user
.
moudle
.
user
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
org.hibernate.validator.constraints.NotBlank
;
...
...
@@ -16,10 +18,13 @@ import javax.validation.constraints.Pattern;
@AllArgsConstructor
@NoArgsConstructor
@ToString
@ApiModel
(
value
=
"发送短信"
)
public
class
SendPhoneVo
{
@NotBlank
(
message
=
"手机号不能为空"
)
@Pattern
(
regexp
=
"^1[3456789]\\d{9}$"
,
message
=
"手机号格式不正确"
)
@ApiModelProperty
(
value
=
"手机号"
,
required
=
true
)
private
String
phone
;
//发送短信的类型 1:注册 2:登录
@ApiModelProperty
(
value
=
"短信类型 传数字 1:注册 2:登录 3:忘记密码 4:修改密码"
,
required
=
true
)
private
Integer
type
;
}
src/main/java/com/lyy/user/util/redis/RedisUtil.java
View file @
b27fa251
...
...
@@ -95,6 +95,10 @@ public class RedisUtil {
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
timeout
,
TimeUnit
.
SECONDS
);
}
public
static
void
set
(
final
String
key
,
final
Object
value
,
final
long
timeout
,
TimeUnit
timeUnit
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
timeout
,
timeUnit
);
}
/**
* 获取普通对象
...
...
@@ -106,7 +110,15 @@ public class RedisUtil {
return
redisTemplate
.
opsForValue
().
get
(
key
);
}
/**
* @description: 获取key的剩余过期时间 如果key不存在 或者没有设置过期时间 返回 -1
* @date: 2023/11/23 9:53
* @param: [key]
* @return: java.lang.Long
**/
public
static
Long
getExpire
(
final
String
key
){
return
redisTemplate
.
getExpire
(
key
);
}
// 存储Hash操作
/**
...
...
src/main/resources/application-dev.yml
View file @
b27fa251
...
...
@@ -34,3 +34,9 @@ spring:
mybatis-plus
:
configuration
:
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
# 打印日志
knife4j
:
# 开启增强配置
enable
:
true
src/main/resources/application-pro.yml
View file @
b27fa251
...
...
@@ -30,3 +30,7 @@ spring:
mybatis-plus
:
configuration
:
log-impl
:
org.apache.ibatis.logging.slf4j.Slf4jImpl
# 打印日志
knife4j
:
# 开启增强配置
enable
:
false
src/main/resources/application-test.yml
View file @
b27fa251
...
...
@@ -30,3 +30,6 @@ spring:
mybatis-plus
:
configuration
:
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
# 打印日志
knife4j
:
# 开启增强配置
enable
:
true
src/main/resources/application.yml
View file @
b27fa251
...
...
@@ -9,7 +9,7 @@
date-format
:
yyyy-MM-dd HH:mm:ss
time-zone
:
GMT+8
server
:
port
:
808
3
port
:
808
8
servlet
:
# 应用的访问路径
context-path
:
/lyy
...
...
@@ -41,3 +41,4 @@ sms:
appUrl
:
https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1
sender
:
8823112010314
signature
:
立业云
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