mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-31 11:49:58 -04:00
Guess people’s names when they’re invited
Most people’s names, especially in government are in the format firstname.lastname@department.gov.uk. This means that you can pretty reliably guess that their name is ‘Firstname Lastname’. When users are invited to Notify we know their email address already. So this commit pre-populates the registration form based on this guess. This is a nice little detail, but it should also stop the browser pre-filling the name field with someone’s email address (which I think happens because the browser assumes a registration form will have an email field).
This commit is contained in:
11
app/utils.py
11
app/utils.py
@@ -25,6 +25,7 @@ from flask import (
|
||||
url_for,
|
||||
)
|
||||
from flask_login import current_user
|
||||
from notifications_utils.formatters import make_quotes_smart
|
||||
from notifications_utils.recipients import RecipientCSV
|
||||
from notifications_utils.template import (
|
||||
EmailPreviewTemplate,
|
||||
@@ -613,3 +614,13 @@ class GovernmentEmailDomain(AgreementInfo):
|
||||
def unicode_truncate(s, length):
|
||||
encoded = s.encode('utf-8')[:length]
|
||||
return encoded.decode('utf-8', 'ignore')
|
||||
|
||||
|
||||
def guess_name_from_email_address(email_address):
|
||||
|
||||
possible_name = re.split(r'[\@\+]', email_address)[0]
|
||||
|
||||
if '.' not in possible_name:
|
||||
return ''
|
||||
|
||||
return make_quotes_smart(possible_name.replace('.', ' ').title())
|
||||
|
||||
Reference in New Issue
Block a user