Clean up login template & form

This commit is contained in:
jeremystretch 2021-05-14 15:32:16 -04:00
parent 06b80b060c
commit 84c6b3cfda
2 changed files with 58 additions and 57 deletions

View File

@ -1,43 +1,46 @@
{% extends 'base.html' %} {% load static %} {% block layout %}
{# User login page. Extends base.html directly to override normal UI layout. #}
{% extends 'base.html' %}
{% load form_helpers %}
{% load static %}
{% block layout %}
<main class="login-container text-center">
{# Login banner #}
{% if settings.BANNER_LOGIN %}
<div class="alert alert-secondary" role="alert">
{{ settings.BANNER_LOGIN|safe }}
</div>
{% endif %}
{# Login form #}
<div class="form-login">
<form action="{% url 'login' %}" method="post">
{% csrf_token %}
{# Logo #}
<div class="mb-4">
{% include 'logo.html' with height=80 %}
</div>
{% csrf_token %} {% if 'next' in request.GET %}
{# Set post-login URL #}
{% if 'next' in request.GET %}
<input type="hidden" name="next" value="{{ request.GET.next }}" />
{% endif %} {% if 'next' in request.POST %}
<input type="hidden" name="next" value="{{ request.POST.next }}" />
{% endif %}
<input
required
type="text"
placeholder="Username"
name="username"
maxlength="150"
id="id_username"
class="form-control"
/>
<input
required
type="password"
placeholder="Password"
name="password"
id="id_password"
class="form-control"
/>
{{ form.username }}
{{ form.password }}
<button type="submit" class="btn btn-primary btn-lg w-100 mt-4">
Sign In
</button>
</form>
</div>
{% load form_helpers %} {% if form.non_field_errors %}
{# Login form errors #}
{% if form.non_field_errors %}
<div class="alert alert-danger" role="alert">
<h4 class="alert-heading">Errors</h4>
<p>
@ -46,6 +49,8 @@
</div>
{% endif %}
</main>
{# Page footer #}
<footer class="footer container-fluid login-footer py-3">
<div class="row align-items-center">
<div class="col-2 col-md-1 mb-0">
@ -61,4 +66,5 @@
</div>
</div>
</footer>
{% endblock %}

View File

@ -6,12 +6,7 @@ from .models import Token
class LoginForm(BootstrapMixin, AuthenticationForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs['placeholder'] = ''
self.fields['password'].widget.attrs['placeholder'] = ''
pass
class PasswordChangeForm(BootstrapMixin, DjangoPasswordChangeForm):