From a81d6447c5e3ff70dd3222b86f64a64f8aaf6907 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 29 May 2020 23:57:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8C=BA=E5=88=86=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E5=92=8C=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zeus/app/controller/rbac/UserApp.kt | 10 +++++++-- .../domain/service/contr/rbac/IUserService.kt | 13 +++++++++-- .../domain/service/impl/rbac/UserService.kt | 22 +++++++++++++++---- 3 files changed, 37 insertions(+), 8 deletions(-) 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, "用户重置密码失败, 如需重置密码请从系统发送的邮件链接中重置") } } From 329a030dc9132342cec378d2fd471df7cc622c71 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 31 May 2020 23:40:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E4=BA=BA=E5=91=98=E7=9A=84=E8=A7=92=E8=89=B2=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/synebula/zeus/query/impl/UserQuery.kt | 10 ++++++---- .../com/synebula/zeus/query/view/SignUserView.kt | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) 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