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"> <main class="login-container text-center">
{# Login banner #}
{% if settings.BANNER_LOGIN %} {% if settings.BANNER_LOGIN %}
<div class="alert alert-secondary" role="alert"> <div class="alert alert-secondary" role="alert">
{{ settings.BANNER_LOGIN|safe }} {{ settings.BANNER_LOGIN|safe }}
</div> </div>
{% endif %} {% endif %}
{# Login form #}
<div class="form-login"> <div class="form-login">
<form action="{% url 'login' %}" method="post"> <form action="{% url 'login' %}" method="post">
{% csrf_token %}
{# Logo #}
<div class="mb-4"> <div class="mb-4">
{% include 'logo.html' with height=80 %} {% include 'logo.html' with height=80 %}
</div> </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 }}" /> <input type="hidden" name="next" value="{{ request.GET.next }}" />
{% endif %} {% if 'next' in request.POST %} {% endif %} {% if 'next' in request.POST %}
<input type="hidden" name="next" value="{{ request.POST.next }}" /> <input type="hidden" name="next" value="{{ request.POST.next }}" />
{% endif %} {% endif %}
<input
required {{ form.username }}
type="text" {{ form.password }}
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"
/>
<button type="submit" class="btn btn-primary btn-lg w-100 mt-4"> <button type="submit" class="btn btn-primary btn-lg w-100 mt-4">
Sign In Sign In
</button> </button>
</form> </form>
</div> </div>
{% load form_helpers %} {% if form.non_field_errors %}
{# Login form errors #}
{% if form.non_field_errors %}
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
<h4 class="alert-heading">Errors</h4> <h4 class="alert-heading">Errors</h4>
<p> <p>
@ -46,6 +49,8 @@
</div> </div>
{% endif %} {% endif %}
</main> </main>
{# Page footer #}
<footer class="footer container-fluid login-footer py-3"> <footer class="footer container-fluid login-footer py-3">
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-2 col-md-1 mb-0"> <div class="col-2 col-md-1 mb-0">
@ -61,4 +66,5 @@
</div> </div>
</div> </div>
</footer> </footer>
{% endblock %} {% endblock %}

View File

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