Refactor login and logout with built-in views

This commit is contained in:
Skia
2015-11-25 16:20:28 +01:00
parent b237cdbaae
commit 04bbf0db5b
5 changed files with 41 additions and 27 deletions

View File

@ -10,7 +10,7 @@
{% block header %}
{% if user.is_authenticated %}Hello, {{ user.username }}!{% endif %}
<ul>
<li><a href="{% url 'core:register' %}">Register</a></li>
<li><a href="">Register</a></li>
<li><a href="{% url 'core:login' %}">Login</a></li>
<li><a href="{% url 'core:logout' %}">Logout</a></li>
<li><a href="{% url 'core:user_list' %}">Users</a></li>

View File

@ -1,14 +1,38 @@
{% extends "core/base.html" %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
<form action="{% url 'core:login' %}" method="post">
{% csrf_token %}
{{ form }}
<p><input type="submit" value="Login!" /></p>
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<form method="post" action="{% url 'core:login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
{# Assumes you setup the password_reset view in your URLconf #}
<p><a href="{% url 'core:password_reset' %}">Lost password?</a></p>
{% endblock %}