Upgrade to ktorm 3.0.0, remove email field from users
This commit is contained in:
@@ -27,7 +27,7 @@ fun Routing.auth(kodein: Kodein) {
|
||||
post("/user/login") {
|
||||
val credential = call.receive<UsernamePasswordCredential>()
|
||||
|
||||
val user = userService.getFromUsername(credential.username)
|
||||
val user = userService.find(credential.username)
|
||||
?: return@post call.respondStatus(HttpStatusCode.Unauthorized)
|
||||
|
||||
if (!BCrypt.checkpw(credential.password, user.password)) {
|
||||
@@ -51,7 +51,7 @@ fun Routing.auth(kodein: Kodein) {
|
||||
return@post call.respondStatus(HttpStatusCode.Unauthorized)
|
||||
}
|
||||
|
||||
if (!userService.userExists(id))
|
||||
if (!userService.exists(id))
|
||||
return@post call.respondStatus(HttpStatusCode.Unauthorized)
|
||||
|
||||
val response = DualToken(
|
||||
@@ -63,9 +63,8 @@ fun Routing.auth(kodein: Kodein) {
|
||||
|
||||
authenticate {
|
||||
get("/user/me") {
|
||||
// retrieve email from token
|
||||
val id = call.principal<UserDbIdPrincipal>()!!.id
|
||||
val info = userService.getUserInfo(id)
|
||||
val info = userService.find(id)
|
||||
if (info != null) call.respond(mapOf("user" to info))
|
||||
else call.respondStatus(HttpStatusCode.Unauthorized)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package be.vandewalleh.routing
|
||||
|
||||
import be.vandewalleh.entities.User
|
||||
import be.vandewalleh.extensions.respondStatus
|
||||
import be.vandewalleh.extensions.userId
|
||||
import be.vandewalleh.services.UserService
|
||||
@@ -9,13 +8,11 @@ import be.vandewalleh.validation.user.registerValidator
|
||||
import io.ktor.application.*
|
||||
import io.ktor.auth.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.request.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
import org.kodein.di.Kodein
|
||||
import org.kodein.di.generic.instance
|
||||
import org.mindrot.jbcrypt.BCrypt
|
||||
import java.time.LocalDateTime
|
||||
|
||||
fun Routing.user(kodein: Kodein) {
|
||||
val userService by kodein.instance<UserService>()
|
||||
@@ -24,32 +21,20 @@ fun Routing.user(kodein: Kodein) {
|
||||
post {
|
||||
val user = call.receiveValidated(registerValidator)
|
||||
|
||||
if (userService.userExists(user.username, user.email))
|
||||
if (userService.exists(user.username))
|
||||
return@post call.respondStatus(HttpStatusCode.Conflict)
|
||||
|
||||
val hashedPassword = BCrypt.hashpw(user.password, BCrypt.gensalt())
|
||||
|
||||
userService.createUser(user.username, user.email, hashedPassword)
|
||||
val newUser = userService.create(user.username, hashedPassword)
|
||||
?: return@post call.respondStatus(HttpStatusCode.Conflict)
|
||||
|
||||
call.respondStatus(HttpStatusCode.Created)
|
||||
call.respond(HttpStatusCode.Created, newUser)
|
||||
}
|
||||
|
||||
authenticate {
|
||||
put {
|
||||
val user = call.receiveValidated(registerValidator)
|
||||
|
||||
if (userService.userExists(user.username, user.email))
|
||||
return@put call.respond(HttpStatusCode.Conflict)
|
||||
|
||||
val hashedPassword = BCrypt.hashpw(user.password, BCrypt.gensalt())
|
||||
|
||||
userService.updateUser(call.userId(), user.username, user.email, hashedPassword)
|
||||
|
||||
call.respondStatus(HttpStatusCode.OK)
|
||||
}
|
||||
|
||||
delete {
|
||||
val status = if (userService.deleteUser(call.userId()))
|
||||
val status = if (userService.delete(call.userId()))
|
||||
HttpStatusCode.OK
|
||||
else
|
||||
HttpStatusCode.NotFound
|
||||
|
||||
Reference in New Issue
Block a user