From 43bab0f58c9b854434c2a847e876f1aa46e7fc28 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 29 May 2020 01:00:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=AA=8C=E8=AF=81=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/synebula/zeus/app/config/ZeusBeans.kt | 8 -------- .../zeus/app/controller/rbac/UserApp.kt | 19 ++++++++++++++++++- .../domain/service/contr/rbac/IUserService.kt | 2 +- .../domain/service/impl/rbac/UserService.kt | 8 +++++--- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/config/ZeusBeans.kt b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/config/ZeusBeans.kt index 7b0ecd4..3120260 100644 --- a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/config/ZeusBeans.kt +++ b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/config/ZeusBeans.kt @@ -19,18 +19,10 @@ import org.springframework.data.mongodb.core.MongoTemplate @Configuration open class ZeusBeans { - @Bean - open fun > genericRepository(template: MongoTemplate) - : IGenericRepository = MongoGenericRepository(template) - @Bean open fun > repository(template: MongoTemplate) : IRepository = MongoRepository(template) - @Bean - open fun mongoGenericQuery(template: MongoTemplate) - : IGenericQuery = MongoGenericQuery(template) - @Bean open fun mongoQuery(template: MongoTemplate, logger: ILogger? = null) : IQuery = MongoQuery(template, logger) 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 3e4e6d0..44dba4b 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 @@ -3,11 +3,13 @@ package com.synebula.zeus.app.controller.rbac import com.synebula.gaea.app.UnionApp import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.data.message.Status +import com.synebula.gaea.data.serialization.json.IJsonSerializer import com.synebula.gaea.log.ILogger import com.synebula.gaea.query.IQuery import com.synebula.zeus.domain.service.cmd.rbac.UserCmd import com.synebula.zeus.domain.service.contr.rbac.IUserService import com.synebula.zeus.query.view.UserView +import org.springframework.beans.factory.annotation.Autowired import org.springframework.web.bind.annotation.* @RestController @@ -21,6 +23,21 @@ class UserApp( service, query, logger ) { + @Autowired + lateinit var serializer: IJsonSerializer + + override fun add(command: UserCmd): HttpMessage { + return this.safeExecute("查询重复用户信息出错, 用户信息: ${serializer.serialize(command)}") { + val list = this.query!!.list(mapOf(Pair("name", command.name)), UserView::class.java) + if (list.count() == 0) + it.from(super.add(command)) + else { + it.status = Status.Failure + it.message = "系统中已存在该用户" + } + } + } + /** * 激活用户 * @@ -50,7 +67,7 @@ class UserApp( @PutMapping("/{key}/password") - fun changePassword(@PathVariable key: String, password: String, token: String): HttpMessage { + fun changePassword(@PathVariable key: String, password: String, token: String?): HttpMessage { return this.safeExecute("修改用户密码出现异常") { it.load((this.service as IUserService).changePassword(key, password, token)) } 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 1994b9c..fb858db 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 @@ -18,7 +18,7 @@ interface IUserService : IService { * @param key 用户ID * @param token 激活密令 */ - fun changePassword(key: String, password: String, token: String): Message + fun changePassword(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 c0def85..f8dc2b5 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 @@ -46,20 +46,22 @@ class UserService( this.repository.update(user, this.clazz) Message(Status.Success, "用户${user.name}激活成功") } else { + logger.warn(this, "用户${user.name}激活失败, {key: ${key}, token: ${token}") Message(Status.Failure, "用户${user.name}激活失败, 请从系统发送的邮件链接激活用户") } } } - override fun changePassword(key: String, password: String, token: String): Message { + override fun changePassword(key: String, password: String, token: String?): Message { val user = this.repository.get(key, this.clazz) - return if (token == user.token) { + return if (user.token == null || token == user.token) { user.password = password.toMd5() user.token = null this.repository.update(user, this.clazz) Message() } else { - Message(Status.Failure, "用户密码修改失败, 请从系统发送的邮件链接中修改密码") + logger.warn(this, "用户${user.name}密码修改失败, 系统密码修改令牌:${user.token}, {key: ${key} , token: ${token}") + Message(Status.Failure, "用户密码修改失败, 如需重置密码请从系统发送的邮件链接中重置") } }