diff --git a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/UserApp.kt b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/UserApp.kt index 44dba4b..bf3a427 100644 --- a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/UserApp.kt +++ b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/UserApp.kt @@ -65,11 +65,17 @@ class UserApp( } } + @PutMapping("/{key}/password/reset") + fun resetPassword(@PathVariable key: String, password: String, token: String?): HttpMessage { + return this.safeExecute("重置用户密码出现异常") { + it.load((this.service as IUserService).resetPassword(key, password, token)) + } + } @PutMapping("/{key}/password") - fun changePassword(@PathVariable key: String, password: String, token: String?): HttpMessage { + fun changePassword(@PathVariable key: String, password: String, newPassword: String): HttpMessage { return this.safeExecute("修改用户密码出现异常") { - it.load((this.service as IUserService).changePassword(key, password, token)) + it.load((this.service as IUserService).changePassword(key, password, newPassword)) } } } \ No newline at end of file diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/contr/rbac/IUserService.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/contr/rbac/IUserService.kt index fb858db..d840fbf 100644 --- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/contr/rbac/IUserService.kt +++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/contr/rbac/IUserService.kt @@ -16,9 +16,18 @@ interface IUserService : IService { * 激活用户 * * @param key 用户ID - * @param token 激活密令 + * @param password 旧密码 + * @param newPassword 新密码 */ - fun changePassword(key: String, password: String, token: String?): Message + fun changePassword(key: String, password: String, newPassword: String): Message + + /** + * 激活用户 + * + * @param key 用户ID + * @param password 新密码 + */ + fun resetPassword(key: String, password: String, token: String?): Message /** diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/impl/rbac/UserService.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/impl/rbac/UserService.kt index f8dc2b5..d070f8c 100644 --- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/impl/rbac/UserService.kt +++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/impl/rbac/UserService.kt @@ -52,16 +52,30 @@ class UserService( } } - override fun changePassword(key: String, password: String, token: String?): Message { + override fun changePassword(key: String, password: String, newPassword: String): Message { val user = this.repository.get(key, this.clazz) - return if (user.token == null || token == user.token) { + return if (user.password == password.toMd5()) { + user.password = newPassword.toMd5() + user.token = null + this.repository.update(user, this.clazz) + Message() + } else { + logger.warn(this, "用户修改${user.name}密码失败, 旧密码验证不通过") + Message(Status.Failure, "用户修改密码失败, 旧密码验证不通过") + } + } + + + override fun resetPassword(key: String, password: String, token: String?): Message { + val user = this.repository.get(key, this.clazz) + return if (token == user.token) { user.password = password.toMd5() user.token = null this.repository.update(user, this.clazz) Message() } else { - logger.warn(this, "用户${user.name}密码修改失败, 系统密码修改令牌:${user.token}, {key: ${key} , token: ${token}") - Message(Status.Failure, "用户密码修改失败, 如需重置密码请从系统发送的邮件链接中重置") + logger.warn(this, "用户重置${user.name}密码失败, 系统密码修改令牌:${user.token}, {key: ${key} , token: ${token}") + Message(Status.Failure, "用户重置密码失败, 如需重置密码请从系统发送的邮件链接中重置") } }