diff --git a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/component/IUserAdded.kt b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/component/IUserAdded.kt
deleted file mode 100644
index 70016ce..0000000
--- a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/component/IUserAdded.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.synebula.zeus.app.component
-
-interface IUserAdded {
- fun added(id: String, name: String)
-}
\ No newline at end of file
diff --git a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/SignInOutApp.kt b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/SignInOutApp.kt
index 33a0e1d..e911aa0 100644
--- a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/SignInOutApp.kt
+++ b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/SignInOutApp.kt
@@ -18,7 +18,7 @@ class SignInOutApp(var query: IUserQuery, override var logger: ILogger) : ISignI
@PostMapping("/in")
override fun signIn(name: String, password: String): HttpMessage {
return this.safeExecute("用户登录出现错误") {
- it.load(this.query.signIn(name, password.toMd5()))
+ it.load(this.query.signIn(name, password))
}
}
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 f858739..3e4e6d0 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
@@ -2,17 +2,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.log.ILogger
import com.synebula.gaea.query.IQuery
-import com.synebula.zeus.app.component.IUserAdded
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.GetMapping
-import org.springframework.web.bind.annotation.PathVariable
-import org.springframework.web.bind.annotation.RequestMapping
-import org.springframework.web.bind.annotation.RestController
+import org.springframework.web.bind.annotation.*
@RestController
@RequestMapping("/users")
@@ -24,14 +20,6 @@ class UserApp(
"用户信息", UserView::class.java,
service, query, logger
) {
- @Autowired
- lateinit var userAdded: IUserAdded
-
- override fun add(command: UserCmd): HttpMessage {
- val msg = super.add(command)
- userAdded.added(msg.data.toString(), command.name)
- return msg
- }
/**
* 激活用户
@@ -39,10 +27,32 @@ class UserApp(
* @param key 用户ID
*/
@GetMapping("/{key}/active")
- fun active(@PathVariable key: String): String {
+ fun active(@PathVariable key: String, token: String): String {
this.safeExecute("激活用户出现异常") {
- (this.service as IUserService).active(key)
+ (this.service as IUserService).active(key, token)
}
return "
激活成功!
"
}
+
+ @GetMapping("/{name}/forgot")
+ fun forgot(@PathVariable name: String): HttpMessage {
+ return this.safeExecute("遗忘用户密码出现异常") {
+ val users = this.query?.list(mapOf(Pair("name", name)), UserView::class.java)
+ if (users != null && users.isNotEmpty()) {
+ it.load((this.service as IUserService).forgotPassword(users[0].id))
+
+ } else {
+ it.status = Status.Failure
+ it.message = "找不到该用户信息"
+ }
+ }
+ }
+
+
+ @PutMapping("/{key}/password")
+ fun changePassword(@PathVariable key: String, password: String, token: String): HttpMessage {
+ return this.safeExecute("修改用户密码出现异常") {
+ it.load((this.service as IUserService).changePassword(key, password, token))
+ }
+ }
}
\ No newline at end of file
diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/User.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/User.kt
index c6698a7..89b9d8b 100644
--- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/User.kt
+++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/User.kt
@@ -8,4 +8,5 @@ class User(override var id: String? = null) : AggregateRoot() {
var realName: String? = null
var phone: String? = null
var role: String = ""
+ var token: String? = null
}
\ No newline at end of file
diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/contr/component/IUserNotifier.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/contr/component/IUserNotifier.kt
new file mode 100644
index 0000000..3138d19
--- /dev/null
+++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/contr/component/IUserNotifier.kt
@@ -0,0 +1,7 @@
+package com.synebula.zeus.domain.service.contr.component
+
+interface IUserNotifier {
+ fun added(id: String, name: String, token: String)
+
+ fun forgot(id: String, name: String, token: String)
+}
\ 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 d03fda9..1994b9c 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
@@ -1,5 +1,6 @@
package com.synebula.zeus.domain.service.contr.rbac
+import com.synebula.gaea.data.message.Message
import com.synebula.gaea.domain.service.IService
interface IUserService : IService {
@@ -7,6 +8,23 @@ interface IUserService : IService {
* 激活用户
*
* @param key 用户ID
+ * @param token 激活密令
*/
- fun active(key: String)
+ fun active(key: String, token: String): Message
+
+ /**
+ * 激活用户
+ *
+ * @param key 用户ID
+ * @param token 激活密令
+ */
+ fun changePassword(key: String, password: String, token: String): Message
+
+
+ /**
+ * 激活用户
+ *
+ * @param key 用户ID
+ */
+ fun forgotPassword(key: String): Message
}
\ No newline at end of file
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 68b6d38..c0def85 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
@@ -2,21 +2,31 @@ package com.synebula.zeus.domain.service.impl.rbac
import com.synebula.gaea.data.IObjectConverter
import com.synebula.gaea.data.message.Message
+import com.synebula.gaea.data.message.Status
import com.synebula.gaea.domain.repository.IRepository
import com.synebula.gaea.domain.service.ICommand
import com.synebula.gaea.domain.service.Service
import com.synebula.gaea.extension.*
import com.synebula.gaea.log.ILogger
import com.synebula.zeus.domain.model.rbac.User
+import com.synebula.zeus.domain.service.contr.component.IUserNotifier
import com.synebula.zeus.domain.service.contr.rbac.IUserService
+import java.util.*
-class UserService(repository: IRepository, converter: IObjectConverter, logger: ILogger) :
+class UserService(
+ repository: IRepository,
+ converter: IObjectConverter,
+ logger: ILogger,
+ var userNotifier: IUserNotifier
+) :
Service(User::class.java, repository, converter, logger), IUserService {
override fun add(command: ICommand): Message {
val user = this.convert(command)
user.password = user.password.toMd5()
+ user.token = UUID.randomUUID().toString()
user.alive = false
this.repository.add(user, this.clazz)
+ userNotifier.added(user.id!!, user.name, user.token!!)
return Message(user.id!!)
}
@@ -25,11 +35,42 @@ class UserService(repository: IRepository, converter: IObjectConverter, logger:
*
* @param key 用户ID
*/
- override fun active(key: String) {
+ override fun active(key: String, token: String): Message {
val user = this.repository.get(key, this.clazz)
- if (!user.alive) {
- user.alive = true
- this.repository.update(user, this.clazz)
+ return if (user.alive) {
+ Message("用户${user.name}无需重复激活")
+ } else {
+ if (token == user.token) {
+ user.alive = true
+ user.token = null
+ this.repository.update(user, this.clazz)
+ Message(Status.Success, "用户${user.name}激活成功")
+ } else {
+ Message(Status.Failure, "用户${user.name}激活失败, 请从系统发送的邮件链接激活用户")
+ }
}
}
+
+ override fun changePassword(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 {
+ Message(Status.Failure, "用户密码修改失败, 请从系统发送的邮件链接中修改密码")
+ }
+ }
+
+ override fun forgotPassword(key: String): Message {
+ val user = this.repository.get(key, this.clazz)
+ return if (user.alive) {
+ user.token = UUID.randomUUID().toString()
+ this.repository.update(user, this.clazz)
+ userNotifier.forgot(user.id!!, user.name, user.token!!)
+ Message()
+ } else
+ Message(Status.Failure, "用户还未激活, 请先激活用户")
+ }
}
\ No newline at end of file
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 eb68eef..37947c9 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
@@ -23,7 +23,7 @@ class UserQuery(template: MongoTemplate) :
.and("password").isEqualTo(password.toMd5())
.and("alive").isEqualTo(true)
)
- val user = this.template.findOne(query, this.clazz!!)
+ val user = this.template.findOne(query, this.clazz!!, "user")
return if (user != null)
Message(SignUserView(user.id, user.name, user.role ?: ""))
else