Commit 759dfd77b0abaaedb0011a1e0f27bbf13db9beaa
Committed by
Sergio Oliveira
1 parent
66797bb2
Exists in
master
and in
39 other branches
Implemented Password Change Feature
Showing
3 changed files
with
73 additions
and
0 deletions
Show diff stats
colab/accounts/urls.py
@@ -4,10 +4,20 @@ from django.conf.urls import patterns, url | @@ -4,10 +4,20 @@ from django.conf.urls import patterns, url | ||
4 | from .views import (UserProfileDetailView, UserProfileUpdateView, LoginView, | 4 | from .views import (UserProfileDetailView, UserProfileUpdateView, LoginView, |
5 | ManageUserSubscriptionsView, ChangeXMPPPasswordView) | 5 | ManageUserSubscriptionsView, ChangeXMPPPasswordView) |
6 | 6 | ||
7 | +from accounts import views | ||
8 | +from django.contrib.auth import views as auth_views | ||
7 | 9 | ||
8 | urlpatterns = patterns('', | 10 | urlpatterns = patterns('', |
9 | url(r'^register/$', 'colab.accounts.views.signup', name='signup'), | 11 | url(r'^register/$', 'colab.accounts.views.signup', name='signup'), |
10 | 12 | ||
13 | + url(r'^change-password/?$', | ||
14 | + auth_views.password_change, | ||
15 | + {'template_name': 'registration/password_change.html'}, | ||
16 | + name='password_change'), | ||
17 | + | ||
18 | + url(r'^change-password-done/?$', | ||
19 | + 'accounts.views.password_changed', name='password_change_done'), | ||
20 | + | ||
11 | url(r'^change-password/$', | 21 | url(r'^change-password/$', |
12 | ChangeXMPPPasswordView.as_view(), name='change_password'), | 22 | ChangeXMPPPasswordView.as_view(), name='change_password'), |
13 | 23 |
colab/accounts/views.py
@@ -275,3 +275,10 @@ class ChangeXMPPPasswordView(UpdateView): | @@ -275,3 +275,10 @@ class ChangeXMPPPasswordView(UpdateView): | ||
275 | _("You've changed your password successfully!") | 275 | _("You've changed your password successfully!") |
276 | ) | 276 | ) |
277 | return response | 277 | return response |
278 | + | ||
279 | +def password_changed(request): | ||
280 | + messages.success(request, _('Your password has been updated!')) | ||
281 | + | ||
282 | + user = request.user | ||
283 | + | ||
284 | + return redirect('user_profile_update', username=user.username) |
src/accounts/templates/registration/password_change.html
0 → 100644
@@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
1 | +{% extends "base.html" %} | ||
2 | +{% load i18n %} | ||
3 | +{% block main-content %} | ||
4 | + | ||
5 | +<div class="row"> | ||
6 | + {% if form.errors %} | ||
7 | + <div class="alert alert-danger"> | ||
8 | + <b> | ||
9 | + {% if form.errors.items|length == 1 %}{% trans "Please correct the error below and try again." %}{% else %}{% trans "Please correct the errors below and try again." %}{% endif %} | ||
10 | + </b> | ||
11 | + </div> | ||
12 | + {% endif %} | ||
13 | +</div> | ||
14 | + | ||
15 | +<br> | ||
16 | +<form action="" method="post" role="form" class="form-horizontal signup"> | ||
17 | + {% csrf_token %} | ||
18 | + | ||
19 | + <div class="row"> | ||
20 | + <div class="col-md-4 col-md-offset-4 col-lg-4 col-lg-offset-4 col-sm-8 col-sm-offset-2 col-xs-12"> | ||
21 | + <div class="panel panel-default"> | ||
22 | + <div class="panel-heading"><h3 class="panel-title">{% trans 'Change Password' %}</h3></div> | ||
23 | + | ||
24 | + <div class="panel-body"> | ||
25 | + <div class="form-group{% if form.old_password.errors %} alert alert-danger has-error{% endif %}"> | ||
26 | + {{ form.old_password.label_tag }} | ||
27 | + <input class="form-control" id="id_old_password" maxlength="254" name="old_password" type="password"> | ||
28 | + {{ form.old_password.errors }} | ||
29 | + </div> | ||
30 | + | ||
31 | + <div class="form-group{% if form.new_password1.errors %} alert alert-danger has-error{% endif %}"> | ||
32 | + {{ form.new_password1.label_tag }} | ||
33 | + <input class="form-control" id="id_new_password1" maxlength="254" name="new_password1" type="password"> | ||
34 | + {{ form.new_password1.errors }} | ||
35 | + </div> | ||
36 | + | ||
37 | + <div class="form-group{% if form.new_password2.errors %} alert alert-danger has-error{% endif %}"> | ||
38 | + {{ form.new_password2.label_tag }} | ||
39 | + <input class="form-control" id="id_new_password2" maxlength="254" name="new_password2" type="password"> | ||
40 | + {{ form.new_password2.errors }} | ||
41 | + </div> | ||
42 | + | ||
43 | + </div> | ||
44 | + </div> | ||
45 | + </div> | ||
46 | + </div> | ||
47 | + | ||
48 | + <div class="row"> | ||
49 | + <div class="submit"> | ||
50 | + <input type="submit" value="{% trans 'Change my password' %}" class="btn btn-primary btn-lg btn-block"> | ||
51 | + </div> | ||
52 | + <script type="text/javascript">document.getElementById("id_old_password").focus();</script> | ||
53 | + </div> | ||
54 | +</form> | ||
55 | + | ||
56 | +{% endblock %} |