security: Moves input field focus javascript to django forms

Signed-off-by: Prachi Srivastava <prachi.chs.2009@gmail.com>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Prachi Srivastava 2019-01-21 12:49:49 +05:30 committed by Sunil Mohan Adapa
parent f43e185a8c
commit 743d976d50
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
13 changed files with 23 additions and 44 deletions

View File

@ -32,6 +32,12 @@ class ConnectionTypeSelectForm(forms.Form):
choices=[(key, value)
for key, value in network.CONNECTION_TYPE_NAMES.items()])
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['connection_type'].widget.attrs.update({
'autofocus': 'autofocus'
})
class ConnectionForm(forms.Form):
"""Base form to create/edit a connection."""

View File

@ -33,9 +33,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_type').focus();
</script>
{% endblock %}

View File

@ -279,6 +279,11 @@ class FirstBootForm(forms.Form):
widget=SubdomainWidget(domain=DOMAIN_APPENDIX),
help_text=_('The subdomain you want to register'))
def __init__(self, *args, **kwargs):
"""Initialize the form."""
super().__init__(*args, **kwargs)
self.fields['code'].widget.attrs.update({'autofocus': 'autofocus'})
def clean_domain(self):
"""Append the domain to the users' subdomain"""
return self.cleaned_data['domain'] + self.DOMAIN_APPENDIX

View File

@ -59,9 +59,3 @@
</div>
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_code').focus();
</script>
{% endblock %}

View File

@ -50,6 +50,7 @@ class AddShareForm(forms.Form):
"""Initialize the form with extra request argument."""
super().__init__(*args, **kwargs)
self.fields['groups'].choices = get_group_choices()
self.fields['name'].widget.attrs.update({'autofocus': 'autofocus'})
def clean_name(self):
"""Check if the name is valid."""

View File

@ -35,9 +35,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_sharing-name').focus();
</script>
{% endblock %}

View File

@ -23,4 +23,9 @@ from captcha.fields import CaptchaField
class AuthenticationForm(DjangoAuthenticationForm):
"""Authentication form with an additional Captcha field."""
captcha = CaptchaField()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})

View File

@ -41,9 +41,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_username').focus();
</script>
{% endblock %}

View File

@ -107,6 +107,7 @@ class CreateUserForm(ValidNewUsernameCheckMixin,
self.request = request
super(CreateUserForm, self).__init__(*args, **kwargs)
self.fields['groups'].choices = get_group_choices()
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
def save(self, commit=True):
"""Save the user model and create LDAP user if required."""
@ -176,6 +177,7 @@ class UserUpdateForm(ValidNewUsernameCheckMixin,
self.username = username
super(UserUpdateForm, self).__init__(*args, **kwargs)
self.is_last_admin_user = get_last_admin_user() == self.username
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
choices = []
@ -286,6 +288,9 @@ class UserChangePasswordForm(SetPasswordForm):
"""Initialize the form with extra request argument."""
self.request = request
super(UserChangePasswordForm, self).__init__(*args, **kwargs)
self.fields['new_password1'].widget.attrs.update({
'autofocus': 'autofocus'
})
def save(self, commit=True):
"""Save the user model and change LDAP password as well."""
@ -309,6 +314,7 @@ class FirstBootForm(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
def save(self, commit=True):
"""Create and log the user in."""

View File

@ -37,8 +37,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_new_password1').focus();
</script>
{% endblock %}

View File

@ -34,8 +34,3 @@
{% endblock %}
{% block page_js %}
<script>
$('#id_username').focus();
</script>
{% endblock %}

View File

@ -43,8 +43,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_username').focus();
</script>
{% endblock %}

View File

@ -43,8 +43,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_username').focus();
</script>
{% endblock %}