commit e732d76b2ea1f6095186a1b5b84926573d620f8b
parent 993dabf4b38a84245902f5ba123a5dfb595fd0c0
Author: Marcello Stanisci <ms@taler.net>
Date: Fri, 8 May 2020 18:17:17 +0200
POST /users
Diffstat:
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -96,12 +96,13 @@ data class NexusUser(
)
/** Instructs the nexus to CREATE a new user */
-data class NexusUserRequest(
- val password: String?
+data class User(
+ val username: String,
+ val password: String
)
/** Collection of all the nexus users existing in the system */
-data class NexusUsers(
+data class Users(
val users: MutableList<NexusUser> = mutableListOf()
)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -151,7 +151,21 @@ fun main() {
*/
post("/users") {
authenticateAdminRequest(call.request.headers["Authorization"])
-
+ val body = call.receive<User>()
+ if (body.username.equals("admin")) throw NexusError(
+ HttpStatusCode.Forbidden,
+ "'admin' is a reserved username"
+ )
+ transaction {
+ NexusUserEntity.new(body.username) {
+ password = SerialBlob(CryptoUtil.hashStringSHA256(body.password))
+ }
+ }
+ call.respondText(
+ "New NEXUS user registered. ID: ${body.username}",
+ ContentType.Text.Plain,
+ HttpStatusCode.OK
+ )
return@post
}
/**