From 13119ccaa6de82076c384d7d83618e390f9b8e05 Mon Sep 17 00:00:00 2001 From: Claude Sonnet 4.6 Date: Wed, 26 Aug 2026 18:24:49 +0000 Subject: feat(users/admin): implement POST /auth/user/create endpoint Parses email/name/password from the JSON body, calls create_verified_user, and returns 201 with the new user's user_id, email, and name. Co-Authored-By: Claude Sonnet 4.6 Reviewed-By: Frederick M. Muriithi Added input validation. --- gn_auth/auth/authorisation/users/views.py | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py index 544074a..cfc6720 100644 --- a/gn_auth/auth/authorisation/users/views.py +++ b/gn_auth/auth/authorisation/users/views.py @@ -61,6 +61,7 @@ from gn_auth.auth.authentication.oauth2.models.oauth2token import ( token_by_access_token) from .models import list_users +from .admin.models import create_verified_user from .masquerade.views import masq from .collections.views import collections @@ -768,4 +769,34 @@ def create_new_user() -> Response: for priv in role.privileges)): raise ForbiddenAccess( "You need the `system:user:create-user` privilege.") - return make_response(jsonify({}), 501) + form = request_json() + errors = {} + try: + email = validate_email( + form.get("email", "").strip(), check_deliverability=False) + except EmailNotValidError as enve: + errors["email"] = ( + f"E-Mail error: {'==>'.join(str(arg) for arg in enve.args)}") + + try: + username = validate_username(form.get("name", "").strip()) + except UsernameError as uerr: + errors["name"] = str(uerr.args[0]) + + try: + passwd = validate_password( + form.get("password", "").strip(), + form.get("password", "").strip()) + except PasswordError as perr: + errors["password"] = str(perr.args[0]) + + if len(tuple(errors.keys())) > 0: + raise UserRegistrationError(tuple(errors.values())) + + user = create_verified_user(conn, email.normalized, username, passwd) + + return make_response(jsonify({ + "user_id": str(user.user_id), + "email": user.email, + "name": user.name + }), 201) -- cgit 1.4.1