diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index 81af3cd..5a0f28c 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -570,7 +570,7 @@ class MyRegisterSerializer(RegisterSerializer): if re.search(r'[^a-z.]', username): raise ValidationError('Invalid characters.') if '..' in username: - raise ValidationError('Can\'t have double periods.') + raise ValidationError('Can\'t have double periods. Remove spaces.') if username.startswith('.') or username.endswith('.'): raise ValidationError('Can\'t start or end with periods.') return super().validate_username(username) diff --git a/apiserver/apiserver/api/utils.py b/apiserver/apiserver/api/utils.py index d802e20..2640a81 100644 --- a/apiserver/apiserver/api/utils.py +++ b/apiserver/apiserver/api/utils.py @@ -340,9 +340,9 @@ def link_old_member(data, user): if data['request_id']: utils_stats.set_progress(data['request_id'], 'Linking old member data...') member.user = user - member.first_name = data['first_name'].title() - member.last_name = data['last_name'].title() - member.preferred_name = data['first_name'].title() + member.first_name = data['first_name'].title().strip() + member.last_name = data['last_name'].title().strip() + member.preferred_name = data['first_name'].title().strip() member.save() models.Transaction.objects.filter(member_id=member.id).update(user=user) @@ -381,9 +381,9 @@ def create_new_member(data, user): models.Member.objects.create( user=user, - first_name=data['first_name'].title(), - last_name=data['last_name'].title(), - preferred_name=data['first_name'].title(), + first_name=data['first_name'].title().strip(), + last_name=data['last_name'].title().strip(), + preferred_name=data['first_name'].title().strip(), ) def register_user(data, user): diff --git a/webclient/src/LoginSignup.js b/webclient/src/LoginSignup.js index 05ede0c..84d7b00 100644 --- a/webclient/src/LoginSignup.js +++ b/webclient/src/LoginSignup.js @@ -79,12 +79,20 @@ export function SignupForm(props) { const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); const handleChange = (e) => handleValues(e, e.currentTarget); - const genUsername = () => ( - input.first_name && input.last_name ? - (input.first_name + '.' + input.last_name).toLowerCase().replace(/ /g, '.') - : - '' - ); + const genUsername = () => { + if (input.first_name && input.last_name) { + let first_name = input.first_name.trim(); + let last_name = input.last_name.trim(); + first_name = first_name.replace(/[^a-z- ]+/g, ''); + last_name = last_name.replace(/[^a-z- ]+/g, ''); + first_name = first_name.replace(/[ -]/g, '.'); + last_name = last_name.replace(/[ -]/g, '.'); + const username = first_name + '.' + last_name; + return username.toLowerCase(); + } else { + return ''; + } + }; const handleSubmit = (e) => { if (loading) return;