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,53 +1,58 @@
{% extends 'base.html' %} {% load static %} {% block layout %} {# User login page. Extends base.html directly to override normal UI layout. #}
<main class="login-container text-center"> {% extends 'base.html' %}
{% if settings.BANNER_LOGIN %} {% load form_helpers %}
<div class="alert alert-secondary" role="alert"> {% load static %}
{{ settings.BANNER_LOGIN|safe }}
</div> {% block layout %}
{% endif %} <main class="login-container text-center">
<div class="form-login">
<form action="{% url 'login' %}" method="post"> {# Login banner #}
<div class="mb-4"> {% if settings.BANNER_LOGIN %}
{% include 'logo.html' with height=80 %} <div class="alert alert-secondary" role="alert">
{{ settings.BANNER_LOGIN|safe }}
</div> </div>
{% csrf_token %} {% if 'next' in request.GET %} {% endif %}
<input type="hidden" name="next" value="{{ request.GET.next }}" />
{% endif %} {% if 'next' in request.POST %} {# Login form #}
<input type="hidden" name="next" value="{{ request.POST.next }}" /> <div class="form-login">
{% endif %} <form action="{% url 'login' %}" method="post">
<input {% csrf_token %}
required
type="text" {# Logo #}
placeholder="Username" <div class="mb-4">
name="username" {% include 'logo.html' with height=80 %}
maxlength="150" </div>
id="id_username"
class="form-control" {# Set post-login URL #}
/> {% if 'next' in request.GET %}
<input <input type="hidden" name="next" value="{{ request.GET.next }}" />
required {% endif %} {% if 'next' in request.POST %}
type="password" <input type="hidden" name="next" value="{{ request.POST.next }}" />
placeholder="Password" {% endif %}
name="password"
id="id_password" {{ form.username }}
class="form-control" {{ form.password }}
/>
<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 %}
<div class="alert alert-danger" role="alert"> {# Login form errors #}
<h4 class="alert-heading">Errors</h4> {% if form.non_field_errors %}
<p> <div class="alert alert-danger" role="alert">
{{ form.non_field_errors }} <h4 class="alert-heading">Errors</h4>
</p> <p>
</div> {{ form.non_field_errors }}
{% endif %} </p>
</main> </div>
<footer class="footer container-fluid login-footer py-3"> {% endif %}
<div class="row align-items-center"> </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"> <div class="col-2 col-md-1 mb-0">
<button type="button" class="btn btn-sm color-mode-toggle" title="Toggle Color Mode"> <button type="button" class="btn btn-sm color-mode-toggle" title="Toggle Color Mode">
<i class="color-mode-icon mdi mdi-lightbulb"></i>&nbsp; <i class="color-mode-icon mdi mdi-lightbulb"></i>&nbsp;
@ -59,6 +64,7 @@
{{ settings.HOSTNAME }} (v{{ settings.VERSION }}) {{ settings.HOSTNAME }} (v{{ settings.VERSION }})
</small> </small>
</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):