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 authored and Sunil Mohan Adapa committed 2019-01-28 17:39:22 -08:00
1 parent f43e185a8c
commit 743d976d50
13 files changed
+23 -44

No files matched your search

+6
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."""
@@ -37,8 +37,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_new_password1').focus();
</script>
{% endblock %}
@@ -34,8 +34,3 @@
{% endblock %}
{% block page_js %}
<script>
$('#id_username').focus();
</script>
{% endblock %}
@@ -43,8 +43,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_username').focus();
</script>
{% endblock %}
@@ -43,8 +43,3 @@
</form>
{% endblock %}
{% block page_js %}
<script>
$('#id_username').focus();
</script>
{% endblock %}