Add possibility to change password

This commit is contained in:
Gabriel Augendre 2016-06-04 12:40:57 +02:00
parent f559c20b65
commit 15da1c8b51
No known key found for this signature in database
GPG key ID: D2B6A5B41FC438B1
4 changed files with 33 additions and 5 deletions

View file

@ -0,0 +1,17 @@
{% extends 'base.html' %}
{% load crispy_forms_filters %}
{% block content %}
<h1>{% block title %}Change password{% endblock %}</h1>
<div id="login">
<form method="post">
{% if next %}
<input type="hidden" name="next" value="{{ next }}"/>
{% endif %}
{% csrf_token %}
{{ form|crispy }}
<button type="submit" class="btn btn-primary">Change password</button>
</form>
</div>
{% endblock %}

View file

@ -1,5 +1,6 @@
from django.conf.urls import url from django.conf.urls import url
from django.contrib.auth.views import login, logout from django.contrib.auth.views import login, logout, password_change
from authentication.views import password_change_done
urlpatterns = [ urlpatterns = [
url(r'^login/$', url(r'^login/$',
@ -12,4 +13,6 @@ urlpatterns = [
{'next_page': 'home'}, {'next_page': 'home'},
name='auth_logout' name='auth_logout'
), ),
url(r'^password/change/$', password_change, {'template_name': 'authentication/change_password.html'}, name='password_change'),
url(r'^password/change/done/$', password_change_done, name='password_change_done'),
] ]

7
authentication/views.py Normal file
View file

@ -0,0 +1,7 @@
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib import messages
def password_change_done(request):
messages.success(request, "Password changed successfully")
return render(request, 'refunds/home.html')

View file

@ -24,20 +24,21 @@
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
{% if not user.is_authenticated %} {% if not user.is_authenticated %}
<li><a href="{% url 'auth_login' %}?next={{ request.path }}">Login</a></li> <li><a href="{% url 'auth_login' %}?next={{ request.path }}">Login</a></li>
{% elif user.is_staff %} {% else %}
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false"> aria-expanded="false">
{% firstof user.get_full_name user.username %} <span class="caret"></span> {% firstof user.get_full_name user.username %} <span class="caret"></span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="{% url 'admin:index' %}">Admin</a></li> {% if user.is_staff %}
<li><a href="{% url 'admin:index' %}">Admin</a></li>
{% endif %}
<li><a href="{% url 'password_change' %}">Change password</a></li>
<li role="separator" class="divider"></li> <li role="separator" class="divider"></li>
<li><a href="{% url 'auth_logout' %}?next={{ request.path }}">Logout</a></li> <li><a href="{% url 'auth_logout' %}?next={{ request.path }}">Logout</a></li>
</ul> </ul>
</li> </li>
{% else %}
<li><a href="{% url 'auth_logout' %}?next={{ request.path }}">Logout</a></li>
{% endif %} {% endif %}
</ul> </ul>
</div><!-- /.navbar-collapse --> </div><!-- /.navbar-collapse -->