registration: Fetch length limits from the backend's actual sizes.

This makes these more likely to remain accurate over time.

Fixes #4211.
This commit is contained in:
Bao Chau
2017-03-22 16:15:06 -07:00
committed by Tim Abbott
parent 30024d0a8f
commit 9b6e648acb
4 changed files with 16 additions and 9 deletions

View File

@@ -38,7 +38,7 @@ Form is validated both client-side using jquery-validate (see signup.js) and ser
{% else %}
<input id="id_full_name" class="required" type="text" name="full_name" placeholder='{{ "Wile E. Coyote" }}'
value="{% if full_name %}{{ full_name }}{% elif form.full_name.value() %}{{ form.full_name.value() }}{% endif %}"
maxlength="100" />
maxlength={{ MAX_NAME_LENGTH}} />
{% if form.full_name.errors %}
{% for error in form.full_name.errors %}
<div class="help-inline text-error">{{ error }}</div>
@@ -56,7 +56,7 @@ Form is validated both client-side using jquery-validate (see signup.js) and ser
<label for="id_password" class="inline-block">{{ _('Password') }}</label>
<input id="id_password" class="required" type="password" name="password"
value="{% if form.password.value() %}{{ form.password.value() }}{% endif %}"
maxlength="100"
maxlength={{ MAX_PASSWORD_LENGTH }}
data-min-length="{{password_min_length}}"
data-min-quality="{{password_min_quality}}"/>
{% if full_name %}
@@ -83,7 +83,7 @@ Form is validated both client-side using jquery-validate (see signup.js) and ser
<input id="id_team_name" class="required" type="text"
placeholder="Acme"
value="{% if form.realm_name.value() %}{{ form.realm_name.value() }}{% endif %}"
name="realm_name" maxlength="40" />
name="realm_name" maxlength={{ MAX_REALM_NAME_LENGTH }} />
{% if form.realm_name.errors %}
{% for error in form.realm_name.errors %}
<div class="help-inline text-error">{{ error }}</div>
@@ -106,7 +106,7 @@ Form is validated both client-side using jquery-validate (see signup.js) and ser
<input id="id_team_subdomain" class="required" type="text"
placeholder="acme"
value="{% if form.realm_subdomain.value() %}{{ form.realm_subdomain.value() }}{% endif %}"
name="realm_subdomain" maxlength="40" />
name="realm_subdomain" maxlength={{ MAX_REALM_SUBDOMAIN_LENGTH }} />
{% if realms_have_subdomains %}
<b> .{{ external_host }}</b>
{% endif %}

View File

@@ -50,13 +50,14 @@ def email_is_not_mit_mailing_list(email):
raise
class RegistrationForm(forms.Form):
MAX_PASSWORD_LENGTH = 100
full_name = forms.CharField(max_length=100)
# The required-ness of the password field gets overridden if it isn't
# actually required for a realm
password = forms.CharField(widget=forms.PasswordInput, max_length=100,
password = forms.CharField(widget=forms.PasswordInput, max_length=MAX_PASSWORD_LENGTH,
required=False)
realm_name = forms.CharField(max_length=100, required=False)
realm_subdomain = forms.CharField(max_length=40, required=False)
realm_name = forms.CharField(max_length=Realm.MAX_REALM_NAME_LENGTH, required=False)
realm_subdomain = forms.CharField(max_length=Realm.MAX_REALM_SUBDOMAIN_LENGTH, required=False)
realm_org_type = forms.ChoiceField(((Realm.COMMUNITY, 'Community'),
(Realm.CORPORATE, 'Corporate')),
initial=Realm.COMMUNITY, required=False)

View File

@@ -103,10 +103,12 @@ def get_realm_emoji_cache_key(realm):
return u'realm_emoji:%s' % (realm.id,)
class Realm(ModelReprMixin, models.Model):
MAX_REALM_NAME_LENGTH = 40
MAX_REALM_SUBDOMAIN_LENGTH = 40
AUTHENTICATION_FLAGS = [u'Google', u'Email', u'GitHub', u'LDAP', u'Dev', u'RemoteUser']
name = models.CharField(max_length=40, null=True) # type: Optional[Text]
string_id = models.CharField(max_length=40, unique=True) # type: Text
name = models.CharField(max_length=MAX_REALM_NAME_LENGTH, null=True) # type: Optional[Text]
string_id = models.CharField(max_length=MAX_REALM_SUBDOMAIN_LENGTH, unique=True) # type: Text
restricted_to_domain = models.BooleanField(default=False) # type: bool
invite_required = models.BooleanField(default=True) # type: bool
invite_by_admins_only = models.BooleanField(default=False) # type: bool

View File

@@ -245,6 +245,10 @@ def accounts_register(request):
'creating_new_team': realm_creation,
'realms_have_subdomains': settings.REALMS_HAVE_SUBDOMAINS,
'password_auth_enabled': password_auth_enabled(realm),
'MAX_REALM_NAME_LENGTH': str(Realm.MAX_REALM_NAME_LENGTH),
'MAX_NAME_LENGTH': str(UserProfile.MAX_NAME_LENGTH),
'MAX_PASSWORD_LENGTH': str(form.MAX_PASSWORD_LENGTH),
'MAX_REALM_SUBDOMAIN_LENGTH': str(Realm.MAX_REALM_SUBDOMAIN_LENGTH)
}
)