mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
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:
parent
f43e185a8c
commit
743d976d50
@ -32,6 +32,12 @@ class ConnectionTypeSelectForm(forms.Form):
|
|||||||
choices=[(key, value)
|
choices=[(key, value)
|
||||||
for key, value in network.CONNECTION_TYPE_NAMES.items()])
|
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):
|
class ConnectionForm(forms.Form):
|
||||||
"""Base form to create/edit a connection."""
|
"""Base form to create/edit a connection."""
|
||||||
|
|||||||
@ -33,9 +33,3 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_js %}
|
|
||||||
<script>
|
|
||||||
$('#id_type').focus();
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
@ -279,6 +279,11 @@ class FirstBootForm(forms.Form):
|
|||||||
widget=SubdomainWidget(domain=DOMAIN_APPENDIX),
|
widget=SubdomainWidget(domain=DOMAIN_APPENDIX),
|
||||||
help_text=_('The subdomain you want to register'))
|
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):
|
def clean_domain(self):
|
||||||
"""Append the domain to the users' subdomain"""
|
"""Append the domain to the users' subdomain"""
|
||||||
return self.cleaned_data['domain'] + self.DOMAIN_APPENDIX
|
return self.cleaned_data['domain'] + self.DOMAIN_APPENDIX
|
||||||
|
|||||||
@ -59,9 +59,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_js %}
|
|
||||||
<script>
|
|
||||||
$('#id_code').focus();
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
@ -50,6 +50,7 @@ class AddShareForm(forms.Form):
|
|||||||
"""Initialize the form with extra request argument."""
|
"""Initialize the form with extra request argument."""
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['groups'].choices = get_group_choices()
|
self.fields['groups'].choices = get_group_choices()
|
||||||
|
self.fields['name'].widget.attrs.update({'autofocus': 'autofocus'})
|
||||||
|
|
||||||
def clean_name(self):
|
def clean_name(self):
|
||||||
"""Check if the name is valid."""
|
"""Check if the name is valid."""
|
||||||
|
|||||||
@ -35,9 +35,3 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_js %}
|
|
||||||
<script>
|
|
||||||
$('#id_sharing-name').focus();
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
@ -23,4 +23,9 @@ from captcha.fields import CaptchaField
|
|||||||
|
|
||||||
|
|
||||||
class AuthenticationForm(DjangoAuthenticationForm):
|
class AuthenticationForm(DjangoAuthenticationForm):
|
||||||
|
"""Authentication form with an additional Captcha field."""
|
||||||
captcha = CaptchaField()
|
captcha = CaptchaField()
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
|
||||||
|
|||||||
@ -41,9 +41,3 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_js %}
|
|
||||||
<script>
|
|
||||||
$('#id_username').focus();
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
@ -107,6 +107,7 @@ class CreateUserForm(ValidNewUsernameCheckMixin,
|
|||||||
self.request = request
|
self.request = request
|
||||||
super(CreateUserForm, self).__init__(*args, **kwargs)
|
super(CreateUserForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['groups'].choices = get_group_choices()
|
self.fields['groups'].choices = get_group_choices()
|
||||||
|
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
"""Save the user model and create LDAP user if required."""
|
"""Save the user model and create LDAP user if required."""
|
||||||
@ -176,6 +177,7 @@ class UserUpdateForm(ValidNewUsernameCheckMixin,
|
|||||||
self.username = username
|
self.username = username
|
||||||
super(UserUpdateForm, self).__init__(*args, **kwargs)
|
super(UserUpdateForm, self).__init__(*args, **kwargs)
|
||||||
self.is_last_admin_user = get_last_admin_user() == self.username
|
self.is_last_admin_user = get_last_admin_user() == self.username
|
||||||
|
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
|
||||||
|
|
||||||
choices = []
|
choices = []
|
||||||
|
|
||||||
@ -286,6 +288,9 @@ class UserChangePasswordForm(SetPasswordForm):
|
|||||||
"""Initialize the form with extra request argument."""
|
"""Initialize the form with extra request argument."""
|
||||||
self.request = request
|
self.request = request
|
||||||
super(UserChangePasswordForm, self).__init__(*args, **kwargs)
|
super(UserChangePasswordForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields['new_password1'].widget.attrs.update({
|
||||||
|
'autofocus': 'autofocus'
|
||||||
|
})
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
"""Save the user model and change LDAP password as well."""
|
"""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):
|
def __init__(self, *args, **kwargs):
|
||||||
self.request = kwargs.pop('request')
|
self.request = kwargs.pop('request')
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.fields['username'].widget.attrs.update({'autofocus': 'autofocus'})
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
"""Create and log the user in."""
|
"""Create and log the user in."""
|
||||||
|
|||||||
@ -37,8 +37,3 @@
|
|||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_js %}
|
|
||||||
<script>
|
|
||||||
$('#id_new_password1').focus();
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
@ -34,8 +34,3 @@
|
|||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_js %}
|
|
||||||
<script>
|
|
||||||
$('#id_username').focus();
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
@ -43,8 +43,3 @@
|
|||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_js %}
|
|
||||||
<script>
|
|
||||||
$('#id_username').focus();
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
@ -43,8 +43,3 @@
|
|||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block page_js %}
|
|
||||||
<script>
|
|
||||||
$('#id_username').focus();
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user