Skip to content
Snippets Groups Projects
Commit 69c88c1a authored by Bjarke Madsen's avatar Bjarke Madsen
Browse files

use given_name from the IDP

parent 7732e17c
No related branches found
No related tags found
1 merge request!72Send email to user when they sign up
This commit is part of merge request !72. Comments created here will be created in the context of that merge request.
...@@ -33,13 +33,14 @@ def admin_required(func): ...@@ -33,13 +33,14 @@ def admin_required(func):
return wraps(func)(wrapper) return wraps(func)(wrapper)
def create_user(email: str, fullname: str, oidc_sub: str): def create_user(email: str, fullname: str, oidc_sub: str, given_name: str):
""" """
Function used to create a new user in the database. Function used to create a new user in the database.
:param email: The email of the user :param email: The email of the user
:param fullname: The full name of the user :param fullname: The full name of the user
:param oidc_sub: The OIDC subject identifier (ID) of the user :param oidc_sub: The OIDC subject identifier (ID) of the user
:param given_name: The given name of the user
:return: The user object :return: The user object
""" """
...@@ -47,7 +48,7 @@ def create_user(email: str, fullname: str, oidc_sub: str): ...@@ -47,7 +48,7 @@ def create_user(email: str, fullname: str, oidc_sub: str):
user = User(email=email, fullname=fullname, oidc_sub=oidc_sub) user = User(email=email, fullname=fullname, oidc_sub=oidc_sub)
session.add(user) session.add(user)
send_admin_signup_notification(user) send_admin_signup_notification(user)
send_user_signup_notification(user) send_user_signup_notification(user, given_name)
return user return user
......
...@@ -75,10 +75,9 @@ def send_admin_signup_notification(user: User): ...@@ -75,10 +75,9 @@ def send_admin_signup_notification(user: User):
send_mail(contents=contents, subject='New user signed up for Compendium') send_mail(contents=contents, subject='New user signed up for Compendium')
def send_user_signup_notification(user: User): def send_user_signup_notification(user: User, given_name: str):
fullname = user.fullname
email = user.email email = user.email
name = f' {given_name}' if given_name else ''
first_name = ' ' + fullname.split()[0] if fullname else '' contents = USER_NOTIFICATION_TEMPLATE.format(name=name)
contents = USER_NOTIFICATION_TEMPLATE.format(name=first_name)
send_mail(contents=contents, subject='You have signed up for the Compendium Survey', recipients=email) send_mail(contents=contents, subject='You have signed up for the Compendium Survey', recipients=email)
...@@ -36,7 +36,7 @@ def authorize(): ...@@ -36,7 +36,7 @@ def authorize():
user = fetch_user(profile) user = fetch_user(profile)
if user is None: if user is None:
# create a new user # create a new user
user = create_user(profile['email'], profile['name'], profile['sub']) user = create_user(profile['email'], profile['name'], profile['sub'], profile['given_name'])
login_user(user) login_user(user)
# redirect to / # redirect to /
......
...@@ -33,4 +33,4 @@ def test_signup_email_user(app, mocker): ...@@ -33,4 +33,4 @@ def test_signup_email_user(app, mocker):
mocker.patch('compendium_v2.email._send_mail', _send_mail) mocker.patch('compendium_v2.email._send_mail', _send_mail)
with test_user(app) as user: with test_user(app) as user:
send_user_signup_notification(user) send_user_signup_notification(user, 'testname')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment