From 1c54bd5923ef15db30af262291f0301b5a328336 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 6 Feb 2020 09:16:58 +0000 Subject: [PATCH] Disallow non-alpha characters in username --- apiserver/apiserver/api/serializers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index 6ea1814..24dee73 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -5,6 +5,7 @@ from rest_framework.exceptions import ValidationError from rest_framework.validators import UniqueValidator from rest_auth.registration.serializers import RegisterSerializer from rest_auth.serializers import UserDetailsSerializer +import re from . import models, fields, utils from .. import settings @@ -351,6 +352,11 @@ class RegistrationSerializer(RegisterSerializer): last_name = serializers.CharField(max_length=32) existing_member = serializers.ChoiceField(['true', 'false']) + def validate_username(self, username): + if re.search(r'[^a-z.]', username): + raise ValidationError('Invalid characters.') + return super().validate_username(username) + def custom_signup(self, request, user): data = request.data