增加重复用户验证等功能
This commit is contained in:
@@ -19,18 +19,10 @@ import org.springframework.data.mongodb.core.MongoTemplate
|
||||
|
||||
@Configuration
|
||||
open class ZeusBeans {
|
||||
@Bean
|
||||
open fun <T : IAggregateRoot<String>> genericRepository(template: MongoTemplate)
|
||||
: IGenericRepository<T, String> = MongoGenericRepository(template)
|
||||
|
||||
@Bean
|
||||
open fun <T : IAggregateRoot<String>> repository(template: MongoTemplate)
|
||||
: IRepository = MongoRepository(template)
|
||||
|
||||
@Bean
|
||||
open fun <T> mongoGenericQuery(template: MongoTemplate)
|
||||
: IGenericQuery<T, String> = MongoGenericQuery(template)
|
||||
|
||||
@Bean
|
||||
open fun <T> mongoQuery(template: MongoTemplate, logger: ILogger? = null)
|
||||
: IQuery = MongoQuery(template, logger)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ interface IUserService : IService<String> {
|
||||
* @param key 用户ID
|
||||
* @param token 激活密令
|
||||
*/
|
||||
fun changePassword(key: String, password: String, token: String): Message<Any>
|
||||
fun changePassword(key: String, password: String, token: String?): Message<Any>
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Any> {
|
||||
override fun changePassword(key: String, password: String, token: String?): Message<Any> {
|
||||
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, "用户密码修改失败, 如需重置密码请从系统发送的邮件链接中重置")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user