Handle username generation better
This commit is contained in:
parent
428383993a
commit
02f080df77
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user