Merge branch 'master' of github.com:synebula-myths/zeus

This commit is contained in:
2020-07-01 10:05:24 +08:00
5 changed files with 46 additions and 13 deletions

View File

@@ -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))
}
}
}

View File

@@ -16,9 +16,18 @@ interface IUserService : IService<String> {
* 激活用户
*
* @param key 用户ID
* @param token 激活密令
* @param password 旧密码
* @param newPassword 新密码
*/
fun changePassword(key: String, password: String, token: String?): Message<Any>
fun changePassword(key: String, password: String, newPassword: String): Message<Any>
/**
* 激活用户
*
* @param key 用户ID
* @param password 新密码
*/
fun resetPassword(key: String, password: String, token: String?): Message<Any>
/**

View File

@@ -52,16 +52,30 @@ class UserService(
}
}
override fun changePassword(key: String, password: String, token: String?): Message<Any> {
override fun changePassword(key: String, password: String, newPassword: String): Message<Any> {
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<Any> {
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, "用户重置密码失败, 如需重置密码请从系统发送的邮件链接中重置")
}
}

View File

@@ -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, "用户名或密码错误")
}
}

View File

@@ -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 = ""
)