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
Branches
Tags
1 merge request!72Send email to user when they sign up
......@@ -33,13 +33,14 @@ def admin_required(func):
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.
:param email: The email of the user
:param fullname: The full name 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
"""
......@@ -47,7 +48,7 @@ def create_user(email: str, fullname: str, oidc_sub: str):
user = User(email=email, fullname=fullname, oidc_sub=oidc_sub)
session.add(user)
send_admin_signup_notification(user)
send_user_signup_notification(user)
send_user_signup_notification(user, given_name)
return user
......
......@@ -75,10 +75,9 @@ def send_admin_signup_notification(user: User):
send_mail(contents=contents, subject='New user signed up for Compendium')
def send_user_signup_notification(user: User):
fullname = user.fullname
def send_user_signup_notification(user: User, given_name: str):
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=first_name)
contents = USER_NOTIFICATION_TEMPLATE.format(name=name)
send_mail(contents=contents, subject='You have signed up for the Compendium Survey', recipients=email)
......@@ -36,7 +36,7 @@ def authorize():
user = fetch_user(profile)
if user is None:
# 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)
# redirect to /
......
......@@ -33,4 +33,4 @@ def test_signup_email_user(app, mocker):
mocker.patch('compendium_v2.email._send_mail', _send_mail)
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