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:
Chris Hill-Scott
2018-07-02 09:08:21 +01:00
parent d08e2b7ee3
commit 3683f99c3b
3 changed files with 51 additions and 6 deletions

View File

@@ -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())