From 1b34969b09941e18c39489c36ee8b91c78d027fd Mon Sep 17 00:00:00 2001 From: Mark Jacobson <52427991+marksparkza@users.noreply.github.com> Date: Thu, 1 Jul 2021 11:35:24 +0200 Subject: [PATCH] Capture the user's name at signup time Ref #18, #15 --- odp/identity/forms.py | 4 ++++ odp/identity/templates/signup.html | 1 + odp/identity/views/signup.py | 3 ++- odp/lib/users.py | 4 +++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/odp/identity/forms.py b/odp/identity/forms.py index f6b9341b..ca4b3ea2 100644 --- a/odp/identity/forms.py +++ b/odp/identity/forms.py @@ -4,6 +4,10 @@ class SignupForm(FlaskForm): + name = StringField( + label='Full name', + validators=[input_required()], + ) email = StringField( label='Email address', filters=[lambda s: s.lower() if s else s], diff --git a/odp/identity/templates/signup.html b/odp/identity/templates/signup.html index 9b52db44..abac1934 100644 --- a/odp/identity/templates/signup.html +++ b/odp/identity/templates/signup.html @@ -8,6 +8,7 @@ {% block content %}
{{ form.csrf_token }} + {{ render_field(form.name) }} {{ render_field(form.email) }} {{ render_field(form.password) }} {{ render_field(form.confirm_password) }} diff --git a/odp/identity/views/signup.py b/odp/identity/views/signup.py index 5b88a89a..8f6218f4 100644 --- a/odp/identity/views/signup.py +++ b/odp/identity/views/signup.py @@ -38,8 +38,9 @@ def signup(): if form.validate(): email = form.email.data password = form.password.data + name = form.name.data try: - create_user_account(email, password) + create_user_account(email, password, name) # the signup (and login) is completed via email verification send_verification_email(email, challenge) diff --git a/odp/lib/users.py b/odp/lib/users.py index e9f92426..5a496cf5 100644 --- a/odp/lib/users.py +++ b/odp/lib/users.py @@ -160,7 +160,7 @@ def validate_email_verification(email): return user.id -def create_user_account(email, password=None): +def create_user_account(email, password=None, name=None): """ Create a new user account with the specified credentials. Password may be omitted if the user is externally authenticated. @@ -172,6 +172,7 @@ def create_user_account(email, password=None): :param email: the input email address :param password: (optional) the input plain-text password + :param name: (optional) the user's personal name :return: the new user id :raises ODPEmailInUse: if the email address is already associated with a user account @@ -191,6 +192,7 @@ def create_user_account(email, password=None): active=True, verified=False, superuser=False, + name=name, ) user.save()