Handle username generation better

This commit is contained in:
Tanner Collin 2021-11-25 06:02:58 +00:00
parent 428383993a
commit 02f080df77
3 changed files with 21 additions and 13 deletions

View File

@ -570,7 +570,7 @@ class MyRegisterSerializer(RegisterSerializer):
if re.search(r'[^a-z.]', username): if re.search(r'[^a-z.]', username):
raise ValidationError('Invalid characters.') raise ValidationError('Invalid characters.')
if '..' in username: 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('.'): if username.startswith('.') or username.endswith('.'):
raise ValidationError('Can\'t start or end with periods.') raise ValidationError('Can\'t start or end with periods.')
return super().validate_username(username) return super().validate_username(username)

View File

@ -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...') if data['request_id']: utils_stats.set_progress(data['request_id'], 'Linking old member data...')
member.user = user member.user = user
member.first_name = data['first_name'].title() member.first_name = data['first_name'].title().strip()
member.last_name = data['last_name'].title() member.last_name = data['last_name'].title().strip()
member.preferred_name = data['first_name'].title() member.preferred_name = data['first_name'].title().strip()
member.save() member.save()
models.Transaction.objects.filter(member_id=member.id).update(user=user) 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( models.Member.objects.create(
user=user, user=user,
first_name=data['first_name'].title(), first_name=data['first_name'].title().strip(),
last_name=data['last_name'].title(), last_name=data['last_name'].title().strip(),
preferred_name=data['first_name'].title(), preferred_name=data['first_name'].title().strip(),
) )
def register_user(data, user): def register_user(data, user):

View File

@ -79,12 +79,20 @@ export function SignupForm(props) {
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
const handleChange = (e) => handleValues(e, e.currentTarget); const handleChange = (e) => handleValues(e, e.currentTarget);
const genUsername = () => ( const genUsername = () => {
input.first_name && input.last_name ? if (input.first_name && input.last_name) {
(input.first_name + '.' + input.last_name).toLowerCase().replace(/ /g, '.') 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) => { const handleSubmit = (e) => {
if (loading) return; if (loading) return;