增加用户注册,登录,激活逻辑
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package com.synebula.zeus.app.component
|
||||
|
||||
interface IUserAdded {
|
||||
fun added(userId: String)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.synebula.zeus.app.controller
|
||||
|
||||
import com.synebula.gaea.app.IApplication
|
||||
import com.synebula.gaea.app.ISignInOut
|
||||
import com.synebula.gaea.app.component.HttpMessage
|
||||
import com.synebula.gaea.extension.toMd5
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.zeus.query.contr.IUserQuery
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sign")
|
||||
class SignInOutApp(var query: IUserQuery, override var logger: ILogger) : ISignInOut, IApplication {
|
||||
override var name: String = "用户登录管理"
|
||||
|
||||
@PostMapping("/in")
|
||||
override fun signIn(name: String, password: String): HttpMessage {
|
||||
return this.safeExecute("用户登录出现错误") {
|
||||
it.load(this.query.signIn(name, password.toMd5()))
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/out")
|
||||
override fun signOut(user: String): HttpMessage {
|
||||
return HttpMessage()
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.synebula.zeus.app.controller
|
||||
|
||||
import com.synebula.gaea.app.UnionTypedApp
|
||||
import com.synebula.gaea.app.component.HttpMessage
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.gaea.query.IQueryTyped
|
||||
import com.synebula.zeus.domain.service.cmd.UserCmd
|
||||
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.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@@ -18,4 +22,25 @@ class UserApp(
|
||||
) : UnionTypedApp<UserCmd, UserView, String>(
|
||||
"用户信息", 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())
|
||||
return msg
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活用户
|
||||
*
|
||||
* @param key 用户ID
|
||||
*/
|
||||
@GetMapping("/{key}/active")
|
||||
fun active(key: String) {
|
||||
this.safeExecute("激活用户出现异常") {
|
||||
(this.service as IUserService).active(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.synebula.zeus.domain.service.cmd
|
||||
package com.synebula.zeus.domain.service.cmd.rbac
|
||||
|
||||
import com.synebula.gaea.domain.service.Command
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.synebula.zeus.domain.service.cmd
|
||||
package com.synebula.zeus.domain.service.cmd.rbac
|
||||
|
||||
import com.synebula.gaea.domain.service.Command
|
||||
|
||||
@@ -2,4 +2,11 @@ package com.synebula.zeus.domain.service.contr.rbac
|
||||
|
||||
import com.synebula.gaea.domain.service.IService
|
||||
|
||||
interface IUserService : IService<String>
|
||||
interface IUserService : IService<String> {
|
||||
/**
|
||||
* 激活用户
|
||||
*
|
||||
* @param key 用户ID
|
||||
*/
|
||||
fun active(key: String)
|
||||
}
|
||||
@@ -1,13 +1,35 @@
|
||||
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.domain.repository.IRepository
|
||||
import com.synebula.gaea.domain.service.ICommand
|
||||
import com.synebula.gaea.domain.service.Service
|
||||
import com.synebula.gaea.extension.toMd5
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.zeus.domain.model.rbac.User
|
||||
import com.synebula.zeus.domain.service.contr.rbac.IUserService
|
||||
|
||||
class UserService(repository: IRepository<User, String>, converter: IObjectConverter, logger: ILogger) :
|
||||
Service<User, String>(User::class.java, repository, converter, logger), IUserService {
|
||||
override fun add(command: ICommand): Message<String> {
|
||||
val user = this.convert(command)
|
||||
user.password = user.password.toMd5()
|
||||
user.alive = false
|
||||
this.repository.add(user)
|
||||
return Message(user.id!!)
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活用户
|
||||
*
|
||||
* @param key 用户ID
|
||||
*/
|
||||
override fun active(key: String) {
|
||||
val user = this.repository.get(key)
|
||||
if (!user.alive) {
|
||||
user.alive = true
|
||||
this.repository.update(user)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.synebula.zeus.query.contr
|
||||
|
||||
import com.synebula.gaea.data.message.Message
|
||||
|
||||
interface IUserQuery {
|
||||
/**
|
||||
* 登录接口
|
||||
*
|
||||
* @param name 用户名
|
||||
* @param password 密码
|
||||
*
|
||||
* @return 返回消息体, 200为登录成功, data为用户ID
|
||||
*/
|
||||
fun signIn(name: String, password: String): Message<String>
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.synebula.zeus.query.impl
|
||||
|
||||
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.MongoQuery
|
||||
import com.synebula.zeus.query.contr.IUserQuery
|
||||
import com.synebula.zeus.query.view.UserView
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
import org.springframework.data.mongodb.core.query.Criteria
|
||||
import org.springframework.data.mongodb.core.query.Query
|
||||
import org.springframework.data.mongodb.core.query.isEqualTo
|
||||
|
||||
class UserQuery(template: MongoTemplate)
|
||||
: MongoQuery<UserView>("user", UserView::class.java, template), IUserQuery {
|
||||
|
||||
override fun signIn(name: String, password: String): Message<String> {
|
||||
this.check()
|
||||
val query = Query.query(
|
||||
Criteria.where("name").isEqualTo(name)
|
||||
.and("password").isEqualTo(password)
|
||||
.and("alive").isEqualTo(true))
|
||||
val user = this.template.findOne(query, this.clazz!!)
|
||||
return if (user != null)
|
||||
Message(user.id)
|
||||
else
|
||||
Message(Status.Failure, "用户名或密码错误")
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.synebula.zeus.query.view
|
||||
|
||||
import com.synebula.gaea.domain.service.Command
|
||||
|
||||
class RoleView {
|
||||
var id: String? = null
|
||||
var name = ""
|
||||
Reference in New Issue
Block a user