修改命名和Message引用

This commit is contained in:
2020-10-30 22:58:38 +08:00
parent dda4411f05
commit 95536cf6f9
4 changed files with 31 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
package com.synebula.zeus.domain.service.ctr.rbac package com.synebula.zeus.domain.service.ctr.rbac
import com.synebula.gaea.data.message.Message import com.synebula.gaea.data.message.DataMessage
import com.synebula.gaea.domain.service.IService import com.synebula.gaea.domain.service.IService
interface IUserService : IService<String> { interface IUserService : IService<String> {
@@ -10,7 +10,7 @@ interface IUserService : IService<String> {
* @param key 用户ID * @param key 用户ID
* @param token 激活密令 * @param token 激活密令
*/ */
fun active(key: String, token: String): Message<Any> fun active(key: String, token: String): DataMessage<Any>
/** /**
* 激活用户 * 激活用户
@@ -19,7 +19,7 @@ interface IUserService : IService<String> {
* @param password 旧密码 * @param password 旧密码
* @param newPassword 新密码 * @param newPassword 新密码
*/ */
fun changePassword(key: String, password: String, newPassword: String): Message<Any> fun changePassword(key: String, password: String, newPassword: String): DataMessage<Any>
/** /**
* 激活用户 * 激活用户
@@ -27,7 +27,7 @@ interface IUserService : IService<String> {
* @param key 用户ID * @param key 用户ID
* @param password 新密码 * @param password 新密码
*/ */
fun resetPassword(key: String, password: String, token: String?): Message<Any> fun resetPassword(key: String, password: String, token: String?): DataMessage<Any>
/** /**
@@ -35,5 +35,5 @@ interface IUserService : IService<String> {
* *
* @param key 用户ID * @param key 用户ID
*/ */
fun forgotPassword(key: String): Message<String> fun forgotPassword(key: String): DataMessage<String>
} }

View File

@@ -1,12 +1,13 @@
package com.synebula.zeus.domain.service.impl.rbac package com.synebula.zeus.domain.service.impl.rbac
import com.synebula.gaea.data.IObjectConverter import com.synebula.gaea.data.IObjectConverter
import com.synebula.gaea.data.message.DataMessage
import com.synebula.gaea.data.message.Message import com.synebula.gaea.data.message.Message
import com.synebula.gaea.data.message.Status import com.synebula.gaea.data.message.Status
import com.synebula.gaea.domain.repository.IRepository import com.synebula.gaea.domain.repository.IRepository
import com.synebula.gaea.domain.service.ICommand import com.synebula.gaea.domain.service.ICommand
import com.synebula.gaea.domain.service.Service import com.synebula.gaea.domain.service.Service
import com.synebula.gaea.extension.toMd5 import com.synebula.gaea.ext.toMd5
import com.synebula.gaea.log.ILogger import com.synebula.gaea.log.ILogger
import com.synebula.zeus.domain.model.rbac.User import com.synebula.zeus.domain.model.rbac.User
import com.synebula.zeus.domain.service.ctr.component.IUserNotifier import com.synebula.zeus.domain.service.ctr.component.IUserNotifier
@@ -26,33 +27,31 @@ class UserService(
init { init {
groupService.addBeforeRemoveListener(this.clazz.name) { id -> groupService.addBeforeRemoveListener(this.clazz.name) { id ->
val msg = Message<String>() val msg = Message()
if (this.repository.count(mapOf(Pair("group", id)), this.clazz) > 0) { if (this.repository.count(mapOf(Pair("group", id)), this.clazz) > 0) {
msg.status = Status.Failure msg.status = Status.Failure
msg.message = "组下还有用户" msg.message = "组下还有用户"
msg.data = msg.message
} }
msg msg
} }
roleService.addBeforeRemoveListener(this.clazz.name) { id -> roleService.addBeforeRemoveListener(this.clazz.name) { id ->
val msg = Message<String>() val msg = Message()
if (this.repository.count(mapOf(Pair("role", id)), this.clazz) > 0) { if (this.repository.count(mapOf(Pair("role", id)), this.clazz) > 0) {
msg.status = Status.Failure msg.status = Status.Failure
msg.message = "角色下还有用户" msg.message = "角色下还有用户"
msg.data = msg.message
} }
msg msg
} }
} }
override fun add(command: ICommand): Message<String> { override fun add(command: ICommand): DataMessage<String> {
val user = this.convert(command) val user = this.convert(command)
user.password = user.password.toMd5() user.password = user.password.toMd5()
user.token = UUID.randomUUID().toString() user.token = UUID.randomUUID().toString()
user.alive = false user.alive = false
this.repository.add(user, this.clazz) this.repository.add(user, this.clazz)
userNotifier.added(user.id!!, user.name, user.token!!) userNotifier.added(user.id!!, user.name, user.token!!)
return Message(user.id!!) return DataMessage(user.id!!)
} }
/** /**
@@ -60,58 +59,58 @@ class UserService(
* *
* @param key 用户ID * @param key 用户ID
*/ */
override fun active(key: String, token: String): Message<Any> { override fun active(key: String, token: String): DataMessage<Any> {
val user = this.repository.get(key, this.clazz) val user = this.repository.get(key, this.clazz)
return if (user.alive) { return if (user.alive) {
Message("用户${user.name}无需重复激活") DataMessage("用户${user.name}无需重复激活")
} else { } else {
if (token == user.token) { if (token == user.token) {
user.alive = true user.alive = true
user.token = null user.token = null
this.repository.update(user, this.clazz) this.repository.update(user, this.clazz)
Message(Status.Success, "用户${user.name}激活成功") DataMessage(Status.Success, "用户${user.name}激活成功")
} else { } else {
logger.warn(this, "用户${user.name}激活失败, {key: ${key}, token: ${token}") logger.warn(this, "用户${user.name}激活失败, {key: ${key}, token: ${token}")
Message(Status.Failure, "用户${user.name}激活失败, 请从系统发送的邮件链接激活用户") DataMessage(Status.Failure, "用户${user.name}激活失败, 请从系统发送的邮件链接激活用户")
} }
} }
} }
override fun changePassword(key: String, password: String, newPassword: String): Message<Any> { override fun changePassword(key: String, password: String, newPassword: String): DataMessage<Any> {
val user = this.repository.get(key, this.clazz) val user = this.repository.get(key, this.clazz)
return if (user.password == password.toMd5()) { return if (user.password == password.toMd5()) {
user.password = newPassword.toMd5() user.password = newPassword.toMd5()
user.token = null user.token = null
this.repository.update(user, this.clazz) this.repository.update(user, this.clazz)
Message() DataMessage()
} else { } else {
logger.warn(this, "用户修改${user.name}密码失败, 旧密码验证不通过") logger.warn(this, "用户修改${user.name}密码失败, 旧密码验证不通过")
Message(Status.Failure, "用户修改密码失败, 旧密码验证不通过") DataMessage(Status.Failure, "用户修改密码失败, 旧密码验证不通过")
} }
} }
override fun resetPassword(key: String, password: String, token: String?): Message<Any> { override fun resetPassword(key: String, password: String, token: String?): DataMessage<Any> {
val user = this.repository.get(key, this.clazz) val user = this.repository.get(key, this.clazz)
return if (token == user.token) { return if (token == user.token) {
user.password = password.toMd5() user.password = password.toMd5()
user.token = null user.token = null
this.repository.update(user, this.clazz) this.repository.update(user, this.clazz)
Message() DataMessage()
} else { } else {
logger.warn(this, "用户重置${user.name}密码失败, 系统密码修改令牌:${user.token}, {key: ${key} , token: ${token}") logger.warn(this, "用户重置${user.name}密码失败, 系统密码修改令牌:${user.token}, {key: ${key} , token: ${token}")
Message(Status.Failure, "用户重置密码失败, 如需重置密码请从系统发送的邮件链接中重置") DataMessage(Status.Failure, "用户重置密码失败, 如需重置密码请从系统发送的邮件链接中重置")
} }
} }
override fun forgotPassword(key: String): Message<String> { override fun forgotPassword(key: String): DataMessage<String> {
val user = this.repository.get(key, this.clazz) val user = this.repository.get(key, this.clazz)
return if (user.alive) { return if (user.alive) {
user.token = UUID.randomUUID().toString() user.token = UUID.randomUUID().toString()
this.repository.update(user, this.clazz) this.repository.update(user, this.clazz)
userNotifier.forgot(user.id!!, user.name, user.token!!) userNotifier.forgot(user.id!!, user.name, user.token!!)
Message() DataMessage()
} else } else
Message(Status.Failure, "用户还未激活, 请先激活用户") DataMessage(Status.Failure, "用户还未激活, 请先激活用户")
} }
} }

View File

@@ -1,6 +1,6 @@
package com.synebula.zeus.query.contr package com.synebula.zeus.query.contr
import com.synebula.gaea.data.message.Message import com.synebula.gaea.data.message.DataMessage
import com.synebula.zeus.query.view.SignUserView import com.synebula.zeus.query.view.SignUserView
import com.synebula.zeus.query.view.UserView import com.synebula.zeus.query.view.UserView
@@ -13,7 +13,7 @@ interface IUserQuery {
* *
* @return 返回消息体, 200为登录成功, data为用户ID * @return 返回消息体, 200为登录成功, data为用户ID
*/ */
fun signIn(name: String, password: String): Message<SignUserView> fun signIn(name: String, password: String): DataMessage<SignUserView>
/** /**
* 列出用户列表 * 列出用户列表

View File

@@ -1,8 +1,8 @@
package com.synebula.zeus.query.impl package com.synebula.zeus.query.impl
import com.synebula.gaea.data.message.Message import com.synebula.gaea.data.message.DataMessage
import com.synebula.gaea.data.message.Status import com.synebula.gaea.data.message.Status
import com.synebula.gaea.extension.toMd5 import com.synebula.gaea.ext.toMd5
import com.synebula.gaea.mongo.whereId import com.synebula.gaea.mongo.whereId
import com.synebula.zeus.query.contr.IUserQuery import com.synebula.zeus.query.contr.IUserQuery
import com.synebula.zeus.query.view.GroupView import com.synebula.zeus.query.view.GroupView
@@ -17,7 +17,7 @@ import org.springframework.data.mongodb.core.query.isEqualTo
class UserQuery(var template: MongoTemplate) : IUserQuery { class UserQuery(var template: MongoTemplate) : IUserQuery {
private val clazz = UserView::class.java private val clazz = UserView::class.java
override fun signIn(name: String, password: String): Message<SignUserView> { override fun signIn(name: String, password: String): DataMessage<SignUserView> {
val query = Query.query( val query = Query.query(
Criteria.where("name").isEqualTo(name) Criteria.where("name").isEqualTo(name)
.and("password").isEqualTo(password.toMd5()) .and("password").isEqualTo(password.toMd5())
@@ -27,7 +27,7 @@ class UserQuery(var template: MongoTemplate) : IUserQuery {
return if (user != null) { return if (user != null) {
val role = this.template.findOne(whereId(user.role), RoleView::class.java, "role") val role = this.template.findOne(whereId(user.role), RoleView::class.java, "role")
val group = this.template.findOne(whereId(user.group), GroupView::class.java, "group") val group = this.template.findOne(whereId(user.group), GroupView::class.java, "group")
Message( DataMessage(
SignUserView( SignUserView(
user.id, user.name, user.realName ?: "", user.id, user.name, user.realName ?: "",
user.role ?: "", role?.name ?: "", user.role ?: "", role?.name ?: "",
@@ -35,7 +35,7 @@ class UserQuery(var template: MongoTemplate) : IUserQuery {
) )
) )
} else } else
Message(Status.Failure, "用户名或密码错误") DataMessage(Status.Failure, "用户名或密码错误")
} }