Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
e433df7e
提交
e433df7e
authored
10月 31, 2020
作者:
Whispa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commit commit
上级
ce4fb304
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
46 行增加
和
6 行删除
+46
-6
UserController.java
...a/com/example/afrishop_v3/controllers/UserController.java
+30
-4
UserTypeEnum.java
...main/java/com/example/afrishop_v3/enums/UserTypeEnum.java
+2
-2
ResetBody.java
src/main/java/com/example/afrishop_v3/models/ResetBody.java
+14
-0
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/UserController.java
浏览文件 @
e433df7e
package
com
.
example
.
afrishop_v3
.
controllers
;
import
com.example.afrishop_v3.base.Result
;
import
com.example.afrishop_v3.bo.KeyConstant
;
import
com.example.afrishop_v3.enums.ResultCodeEnum
;
import
com.example.afrishop_v3.models.ResetBody
;
import
com.example.afrishop_v3.models.TbCfUserInfo
;
import
com.example.afrishop_v3.repository.UserRepository
;
import
com.example.afrishop_v3.security.services.AuthenticationUser
;
...
...
@@ -10,23 +10,24 @@ import com.example.afrishop_v3.util.SMSUtil;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
import
java.util.Optional
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
@RestController
@RequestMapping
(
"user"
)
public
class
UserController
extends
Controller
{
private
final
UserRepository
repository
;
private
final
AuthenticationUser
user
;
private
final
PasswordEncoder
encoder
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
UserController
.
class
);
public
UserController
(
UserRepository
repository
,
AuthenticationUser
user
)
{
public
UserController
(
UserRepository
repository
,
AuthenticationUser
user
,
PasswordEncoder
encoder
)
{
this
.
repository
=
repository
;
this
.
user
=
user
;
this
.
encoder
=
encoder
;
}
@PutMapping
(
"bindPhoneOrEmail"
)
...
...
@@ -115,6 +116,31 @@ public class UserController extends Controller {
return
result
;
}
@PutMapping
public
Result
updatePassword
(
@RequestBody
ResetBody
body
){
if
(
body
==
null
||
body
.
getNewPassword
()
==
null
||
body
.
getOldPassword
()
==
null
||
body
.
getOldPassword
().
isEmpty
()
||
body
.
getNewPassword
().
isEmpty
()){
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Empty body"
);
}
TbCfUserInfo
user
=
this
.
user
.
user
();
boolean
matches
=
encoder
.
matches
(
body
.
getOldPassword
(),
user
.
getPassword
());
if
(
!
matches
){
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Old password does not match"
);
}
user
.
setPassword
(
encoder
.
encode
(
body
.
getNewPassword
()));
repository
.
save
(
user
);
return
new
Result
<>(
user
);
}
@PutMapping
public
Result
updateUser
(
@RequestBody
TbCfUserInfo
info
)
{
TbCfUserInfo
user
=
this
.
user
.
user
();
...
...
src/main/java/com/example/afrishop_v3/enums/UserTypeEnum.java
浏览文件 @
e433df7e
...
...
@@ -8,8 +8,8 @@ public enum UserTypeEnum {
FACEBOOK
(
2
,
"facebook"
),
TWITTER
(
3
,
"推特"
),
PHONE
(
4
,
"手机"
),
UN_KNOW
(
5
,
"未知"
)
;
UN_KNOW
(
5
,
"未知"
)
,
GOOGLE
(
6
,
"Google"
)
;
//成员变量(常量)
private
final
int
code
;
...
...
src/main/java/com/example/afrishop_v3/models/ResetBody.java
0 → 100644
浏览文件 @
e433df7e
package
com
.
example
.
afrishop_v3
.
models
;
public
class
ResetBody
{
private
String
oldPassword
;
private
String
newPassword
;
public
String
getNewPassword
()
{
return
newPassword
;
}
public
String
getOldPassword
()
{
return
oldPassword
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论