[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 06/08: POST /users
From: |
gnunet |
Subject: |
[libeufin] 06/08: POST /users |
Date: |
Fri, 08 May 2020 20:04:50 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
commit e732d76b2ea1f6095186a1b5b84926573d620f8b
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri May 8 18:17:17 2020 +0200
POST /users
---
nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt | 7 ++++---
nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 16 +++++++++++++++-
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
index bb0a18b..ed7d62b 100644
--- 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
index f55e4e8..f4c5814 100644
--- 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
}
/**
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [libeufin] branch master updated (64b3929 -> f73bdad), gnunet, 2020/05/08
- [libeufin] 04/08: GET /user, gnunet, 2020/05/08
- [libeufin] 01/08: Comments., gnunet, 2020/05/08
- [libeufin] 06/08: POST /users,
gnunet <=
- [libeufin] 02/08: new API., gnunet, 2020/05/08
- [libeufin] 05/08: admin authentication helper, gnunet, 2020/05/08
- [libeufin] 03/08: fix compilation, gnunet, 2020/05/08
- [libeufin] 07/08: add GET /bank-accounts, fix GET /user., gnunet, 2020/05/08
- [libeufin] 08/08: POST preapred-payments/submit, gnunet, 2020/05/08