diff options
| -rw-r--r-- | gn_auth/auth/authorisation/users/views.py | 33 |
1 files changed, 32 insertions, 1 deletions
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) |
