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, "用户重置密码失败, 如需重置密码请从系统发送的邮件链接中重置") } } diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/UserQuery.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/UserQuery.kt index 37947c9..425cbf7 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/UserQuery.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/UserQuery.kt @@ -4,8 +4,9 @@ import com.synebula.gaea.data.message.Message import com.synebula.gaea.data.message.Status import com.synebula.gaea.extension.toMd5 import com.synebula.gaea.mongo.query.MongoGenericQuery -import com.synebula.gaea.mongo.query.MongoQuery +import com.synebula.gaea.mongo.whereId import com.synebula.zeus.query.contr.IUserQuery +import com.synebula.zeus.query.view.RoleView import com.synebula.zeus.query.view.SignUserView import com.synebula.zeus.query.view.UserView import org.springframework.data.mongodb.core.MongoTemplate @@ -24,9 +25,10 @@ class UserQuery(template: MongoTemplate) : .and("alive").isEqualTo(true) ) val user = this.template.findOne(query, this.clazz!!, "user") - return if (user != null) - Message(SignUserView(user.id, user.name, user.role ?: "")) - else + return if (user != null) { + val role = this.template.findOne(whereId(user.role), RoleView::class.java, "role") + Message(SignUserView(user.id, user.name, user.realName ?: "", user.role ?: "", role?.name ?: "")) + } else Message(Status.Failure, "用户名或密码错误") } } \ No newline at end of file diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/SignUserView.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/SignUserView.kt index d583f4b..3351191 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/SignUserView.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/SignUserView.kt @@ -3,5 +3,7 @@ package com.synebula.zeus.query.view class SignUserView( var id: String = "", var name: String = "", - var role: String = "" + var realName: String = "", + var role: String = "", + var roleName: String = "" ) \ No newline at end of file