diff --git a/core/templates/core/password_change_done.html b/core/templates/core/password_change_done.html index 6f3636a8..f3fa2d2a 100644 --- a/core/templates/core/password_change_done.html +++ b/core/templates/core/password_change_done.html @@ -2,10 +2,11 @@ {% block content %} -You successfully changed your password! {% if form.errors %}

Your passwords didn't match. Please try again.

+{% else %} +You successfully changed your password! {% endif %} {% endblock %} diff --git a/core/templates/core/password_reset.html b/core/templates/core/password_reset.html new file mode 100644 index 00000000..16f7591c --- /dev/null +++ b/core/templates/core/password_reset.html @@ -0,0 +1,9 @@ +{% extends "core/base.html" %} + +{% block content %} +
+{% csrf_token %} +{{ form.as_p }} + +
+{% endblock %} diff --git a/core/templates/core/password_reset_complete.html b/core/templates/core/password_reset_complete.html new file mode 100644 index 00000000..c524fdbe --- /dev/null +++ b/core/templates/core/password_reset_complete.html @@ -0,0 +1,8 @@ +{% extends "core/base.html" %} + +{% block content %} +

You successfully reset your password!

+Login +{% endblock %} + + diff --git a/core/templates/core/password_reset_confirm.html b/core/templates/core/password_reset_confirm.html new file mode 100644 index 00000000..07b667b6 --- /dev/null +++ b/core/templates/core/password_reset_confirm.html @@ -0,0 +1,10 @@ +{% extends "core/base.html" %} + +{% block content %} +
+{% csrf_token %} +{{ form.as_p }} + +
+{% endblock %} + diff --git a/core/templates/core/password_reset_email.html b/core/templates/core/password_reset_email.html new file mode 100644 index 00000000..0f3b0823 --- /dev/null +++ b/core/templates/core/password_reset_email.html @@ -0,0 +1,15 @@ +{% load i18n %}{% autoescape off %} +{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %} + +{% trans "Please go to the following page and choose a new password:" %} +{% block reset_link %} +{{ protocol }}://{{ domain }}{% url 'core:password_reset_confirm' uidb64=uid token=token %} +{% endblock %} +{% trans "Your username, in case you've forgotten:" %} {{ user.get_username }} + +{% trans "Thanks for using our site!" %} + +{% blocktrans %}The {{ site_name }} team{% endblocktrans %} + +{% endautoescape %} + diff --git a/core/urls.py b/core/urls.py index 94b4507b..4f3b2186 100644 --- a/core/urls.py +++ b/core/urls.py @@ -3,15 +3,15 @@ from django.conf.urls import url, include from core.views import * urlpatterns = [ - url('^', include('django.contrib.auth.urls')), + #url('^', include('django.contrib.auth.urls')), url(r'^$', index, name='index'), - url(r'^login$', login, name='login'), - url(r'^logout$', logout, name='logout'), - url(r'^password_change$', password_change, name='password_change'), + url(r'^login/$', login, name='login'), + url(r'^logout/$', logout, name='logout'), + url(r'^password_change/$', password_change, name='password_change'), url(r'^password_change/done$', password_change_done, name='password_change_done'), - url(r'^password_reset$', password_reset, name='password_reset'), + url(r'^password_reset/$', password_reset, name='password_reset'), url(r'^password_reset/done$', password_reset_done, name='password_reset_done'), url(r'^reset/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', password_reset_confirm, name='password_reset_confirm'), url(r'^reset/done/$', password_reset_complete, name='password_reset_complete'), diff --git a/core/views/user.py b/core/views/user.py index 7d6512d7..39f4fc1f 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -3,6 +3,7 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.contrib.auth import logout as auth_logout, views from django.contrib.auth.forms import PasswordChangeForm from django.core.urlresolvers import reverse +from django.core.mail import send_mail import logging from core.views.forms import RegisteringForm, LoginForm, UserEditForm @@ -26,7 +27,7 @@ def password_change(request): """ Allows a user to change its password """ - return views.password_change(request, template_name="core/password_change.html") + return views.password_change(request, template_name="core/password_change.html", post_change_redirect=reverse("core:password_change_done")) def password_change_done(request): """ @@ -34,16 +35,27 @@ def password_change_done(request): """ return views.password_change_done(request, template_name="core/password_change_done.html") -def password_reset_confirm(request): - pass - -def password_reset_complete(request): - pass +def password_reset(request): + return views.password_reset(request, + template_name="core/password_reset.html", + email_template_name="core/password_reset_email.html", + post_reset_redirect="core:password_reset", + ) def password_reset_done(request): + return views.password_reset_done(request) pass -def password_reset(request): +def password_reset_confirm(request, uidb64=None, token=None): + return views.password_reset_confirm(request, uidb64=uidb64, token=token, + post_reset_redirect="core:password_reset_complete", + template_name="core/password_reset_confirm.html", + ) + +def password_reset_complete(request): + return views.password_reset_complete(request, + template_name="core/password_reset_complete.html", + ) pass def register(request): diff --git a/sith/settings.py b/sith/settings.py index 2757b3c6..feff21f0 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -101,7 +101,15 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = '/static/' + +# Auth configuration + AUTH_USER_MODEL = 'core.User' LOGIN_URL = '/login' LOGOUT_URL = '/logout' LOGIN_REDIRECT_URL = '/' +DEFAULT_FROM_EMAIL="bibou@git.an" + +# Email +EMAIL_HOST="localhost" +EMAIL_PORT=25 diff --git a/sith/urls.py b/sith/urls.py index aa47ef80..a76c6f4e 100644 --- a/sith/urls.py +++ b/sith/urls.py @@ -17,6 +17,6 @@ from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ - url(r'^', include('core.urls', namespace="core")), + url(r'^', include('core.urls', namespace="core", app_name="core")), url(r'^admin/', include(admin.site.urls)), ]