-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature-edit-password #21
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,4 +98,22 @@ class UserDAO( | |
this.getOne(QueryWrapper<SqlUserDO>().eq("phone", phone)) | ||
} | ||
} | ||
|
||
/** | ||
* ## 修改密码 | ||
* 用户通过旧密码进行修改密码 | ||
* | ||
* @param uuid 用户UUID | ||
* @param password 新密码 | ||
* @return 是否修改成功 | ||
*/ | ||
fun editPassword(uuid: String, password: String): Boolean { | ||
val user = this.getUserByUUID(uuid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在服务层已判断,无需重复判断 |
||
return if (user != null) { | ||
user.password = password | ||
this.update(user, QueryWrapper<SqlUserDO>().eq("uuid", uuid)) | ||
} else { | ||
false | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.frontleaves.fantasticeditor.models.vo.api.auth; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* 用户修改密码VO | ||
* <p> | ||
* 用于接收用户修改密码的信息 | ||
* | ||
* @author DC_DC | ||
* @version v1.0.0 | ||
* @since v1.0.0 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
public class AuthUserEditPasswordVO { | ||
@NotBlank(message = "原密码不能为空") | ||
public String oldPassword; | ||
@NotBlank(message = "新密码不能为空") | ||
public String newPassword; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import com.frontleaves.fantasticeditor.models.entity.redis.RedisSmsCodeDO; | ||
import com.frontleaves.fantasticeditor.models.entity.sql.SqlRoleDO; | ||
import com.frontleaves.fantasticeditor.models.entity.sql.SqlUserDO; | ||
import com.frontleaves.fantasticeditor.models.vo.api.auth.AuthUserEditPasswordVO; | ||
import com.frontleaves.fantasticeditor.models.vo.api.auth.AuthUserLoginVO; | ||
import com.frontleaves.fantasticeditor.models.vo.api.auth.AuthUserRegisterVO; | ||
import com.frontleaves.fantasticeditor.services.interfaces.MailService; | ||
|
@@ -42,6 +43,7 @@ | |
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
|
@@ -255,4 +257,34 @@ public void sendMailVerify(@NotNull final String email) { | |
// 发送验证码 | ||
mailService.sendVerifyCodeMail(email, getNumberCode, MailTemplateEnum.USER_REGISTER); | ||
} | ||
|
||
@Override | ||
public boolean editPassword( | ||
@NotNull final AuthUserEditPasswordVO authUserEditPasswordVO, | ||
@NotNull final String uuid | ||
) { | ||
// 获取用户信息 | ||
SqlUserDO getUser = userDAO.getUserByUUID(uuid); | ||
if (getUser == null) { | ||
throw new BusinessException("用户不存在", ErrorCode.USER_NOT_EXIST); | ||
} | ||
// 校验旧密码是否正确 | ||
if (!Util.INSTANCE.verifyPassword(authUserEditPasswordVO.getOldPassword(), getUser.getPassword())) { | ||
throw new BusinessException("旧密码错误", ErrorCode.OPERATION_FAILED); | ||
} | ||
// 判断新旧密码是否相同 | ||
if (authUserEditPasswordVO.getOldPassword().equals(authUserEditPasswordVO.getNewPassword())) { | ||
throw new BusinessException("新旧密码相同", ErrorCode.OPERATION_FAILED); | ||
} | ||
// 修改密码 | ||
if (userDAO.editPassword(uuid, Util.INSTANCE.encryptPassword(authUserEditPasswordVO.getNewPassword()))) { | ||
mailService.sendMail( | ||
getUser.getEmail(), | ||
MailTemplateEnum.USER_EDIT_PASSWORD, Map.of("username", getUser.getUsername()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 要换行就都换 |
||
); | ||
return true; | ||
} else { | ||
throw new BusinessException("修改失败", ErrorCode.OPERATION_FAILED); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
package com.frontleaves.fantasticeditor.services.interfaces | ||
|
||
import com.frontleaves.fantasticeditor.models.dto.UserCurrentDTO | ||
import com.frontleaves.fantasticeditor.models.vo.api.auth.AuthUserEditPasswordVO | ||
import com.frontleaves.fantasticeditor.models.vo.api.auth.AuthUserLoginVO | ||
import com.frontleaves.fantasticeditor.models.vo.api.auth.AuthUserRegisterVO | ||
|
||
|
@@ -72,4 +73,5 @@ interface UserService { | |
* @return 成功发送返回真,否则返回假 | ||
*/ | ||
fun sendMailVerify(email: String) | ||
fun editPassword(authUserEditPasswordVO: AuthUserEditPasswordVO, uuid: String): Boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. javaDoc |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- | ||
~ ******************************************************************************** | ||
~ Copyright (C) 2024-NOW(至今) 妙笔智编 | ||
~ Author: 锋楪技术团队 | ||
~ | ||
~ 本文件包含 妙笔智编「FantasticEditor」 的源代码,该项目的所有源代码均遵循MIT开源许可证协议。 | ||
~ 本代码仅允许在十三届软件杯比赛授权比赛方可直接使用 | ||
~ ******************************************************************************** | ||
~ 免责声明: | ||
~ 使用本软件的风险由用户自担。作者或版权持有人在法律允许的最大范围内, | ||
~ 对因使用本软件内容而导致的任何直接或间接的损失不承担任何责任。 | ||
~ ******************************************************************************** | ||
--> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>修改密码成功</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
若不是发送邮件最后的布尔是 false,已提交 javaDoc 文档修正