mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
forms: Extract check_subdomain_available.
This should make it easier to call this check from other code paths.
This commit is contained in:
@@ -49,6 +49,24 @@ def email_is_not_mit_mailing_list(email):
|
|||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def check_subdomain_available(subdomain):
|
||||||
|
# type: (str) -> None
|
||||||
|
error_strings = {
|
||||||
|
'too short': _("Subdomain needs to have length 3 or greater."),
|
||||||
|
'extremal dash': _("Subdomain cannot start or end with a '-'."),
|
||||||
|
'bad character': _("Subdomain can only have lowercase letters, numbers, and '-'s."),
|
||||||
|
'unavailable': _("Subdomain unavailable. Please choose a different one.")}
|
||||||
|
|
||||||
|
if len(subdomain) < 3:
|
||||||
|
raise ValidationError(error_strings['too short'])
|
||||||
|
if subdomain[0] == '-' or subdomain[-1] == '-':
|
||||||
|
raise ValidationError(error_strings['extremal dash'])
|
||||||
|
if not re.match('^[a-z0-9-]*$', subdomain):
|
||||||
|
raise ValidationError(error_strings['bad character'])
|
||||||
|
if is_reserved_subdomain(subdomain) or \
|
||||||
|
get_realm(subdomain) is not None:
|
||||||
|
raise ValidationError(error_strings['unavailable'])
|
||||||
|
|
||||||
class RegistrationForm(forms.Form):
|
class RegistrationForm(forms.Form):
|
||||||
MAX_PASSWORD_LENGTH = 100
|
MAX_PASSWORD_LENGTH = 100
|
||||||
full_name = forms.CharField(max_length=UserProfile.MAX_NAME_LENGTH)
|
full_name = forms.CharField(max_length=UserProfile.MAX_NAME_LENGTH)
|
||||||
@@ -81,24 +99,10 @@ class RegistrationForm(forms.Form):
|
|||||||
|
|
||||||
def clean_realm_subdomain(self):
|
def clean_realm_subdomain(self):
|
||||||
# type: () -> str
|
# type: () -> str
|
||||||
error_strings = {
|
|
||||||
'too short': _("Subdomain needs to have length 3 or greater."),
|
|
||||||
'extremal dash': _("Subdomain cannot start or end with a '-'."),
|
|
||||||
'bad character': _("Subdomain can only have lowercase letters, numbers, and '-'s."),
|
|
||||||
'unavailable': _("Subdomain unavailable. Please choose a different one.")}
|
|
||||||
|
|
||||||
subdomain = self.cleaned_data['realm_subdomain']
|
subdomain = self.cleaned_data['realm_subdomain']
|
||||||
if not subdomain:
|
if not subdomain:
|
||||||
return ''
|
return ''
|
||||||
if len(subdomain) < 3:
|
check_subdomain_available(subdomain)
|
||||||
raise ValidationError(error_strings['too short'])
|
|
||||||
if subdomain[0] == '-' or subdomain[-1] == '-':
|
|
||||||
raise ValidationError(error_strings['extremal dash'])
|
|
||||||
if not re.match('^[a-z0-9-]*$', subdomain):
|
|
||||||
raise ValidationError(error_strings['bad character'])
|
|
||||||
if is_reserved_subdomain(subdomain) or \
|
|
||||||
get_realm(subdomain) is not None:
|
|
||||||
raise ValidationError(error_strings['unavailable'])
|
|
||||||
return subdomain
|
return subdomain
|
||||||
|
|
||||||
class ToSForm(forms.Form):
|
class ToSForm(forms.Form):
|
||||||
|
|||||||
Reference in New Issue
Block a user