diff --git a/passbook/core/auth/factors/password.py b/passbook/core/auth/factors/password.py
index 3ea1c4689..2d6d1514e 100644
--- a/passbook/core/auth/factors/password.py
+++ b/passbook/core/auth/factors/password.py
@@ -1,9 +1,11 @@
"""passbook multi-factor authentication engine"""
from logging import getLogger
+from django.contrib import messages
from django.contrib.auth import authenticate
from django.core.exceptions import PermissionDenied
from django.forms.utils import ErrorList
+from django.shortcuts import redirect
from django.utils.translation import gettext as _
from django.views.generic import FormView
@@ -21,6 +23,19 @@ class PasswordFactor(FormView, AuthenticationFactor):
form_class = PasswordFactorForm
template_name = 'login/factors/backend.html'
+ def get_context_data(self, **kwargs):
+ kwargs['show_password_forget_notice'] = CONFIG.y('passbook.password_reset.enabled')
+ return super().get_context_data(**kwargs)
+
+ def get(self, request, *args, **kwargs):
+ if 'password-forgotten' in request.GET:
+ # TODO: Save nonce key in database for password reset
+ # TODO: Send email to user
+ self.authenticator.cleanup()
+ messages.success(request, _('Check your E-Mails for a password reset link.'))
+ return redirect('passbook_core:auth-login')
+ return super().get(request, *args, **kwargs)
+
def form_valid(self, form):
"""Authenticate against django's authentication backend"""
uid_fields = CONFIG.y('passbook.uid_fields')
diff --git a/passbook/core/auth/view.py b/passbook/core/auth/view.py
index 74914e91b..7a300e3d8 100644
--- a/passbook/core/auth/view.py
+++ b/passbook/core/auth/view.py
@@ -111,7 +111,7 @@ class AuthenticationView(UserPassesTestMixin, View):
"""Show error message, user cannot login.
This should only be shown if user authenticated successfully, but is disabled/locked/etc"""
LOGGER.debug("User invalid")
- self._cleanup()
+ self.cleanup()
return redirect(reverse('passbook_core:auth-denied'))
def _user_passed(self):
@@ -121,13 +121,13 @@ class AuthenticationView(UserPassesTestMixin, View):
login(self.request, self.pending_user, backend=backend)
LOGGER.debug("Logged in user %s", self.pending_user)
# Cleanup
- self._cleanup()
+ self.cleanup()
next_param = self.request.GET.get('next', None)
if next_param and is_url_absolute(next_param):
return redirect(next_param)
return redirect(reverse('passbook_core:overview'))
- def _cleanup(self):
+ def cleanup(self):
"""Remove temporary data from session"""
session_keys = [self.SESSION_FACTOR, self.SESSION_PENDING_FACTORS,
self.SESSION_PENDING_USER, self.SESSION_USER_BACKEND, ]
diff --git a/passbook/core/templates/login/factors/backend.html b/passbook/core/templates/login/factors/backend.html
index b4b181d1d..a88dd6b0a 100644
--- a/passbook/core/templates/login/factors/backend.html
+++ b/passbook/core/templates/login/factors/backend.html
@@ -2,3 +2,8 @@
{% load i18n %}
+{% block beneath_form %}
+{% if show_password_forget_notice %}
+{% trans 'Forgot password?' %}
+{% endif %}
+{% endblock %}
diff --git a/passbook/core/templates/login/form.html b/passbook/core/templates/login/form.html
index 64ebb2c83..5aac0afba 100644
--- a/passbook/core/templates/login/form.html
+++ b/passbook/core/templates/login/form.html
@@ -11,6 +11,8 @@
{% block above_form %}
{% endblock %}
{% include 'partials/form_login.html' %}
+ {% block beneath_form %}
+ {% endblock %}
{% if show_sign_up_notice %}
diff --git a/passbook/core/templates/partials/form_login.html b/passbook/core/templates/partials/form_login.html
index 608bd9154..944dbea8a 100644
--- a/passbook/core/templates/partials/form_login.html
+++ b/passbook/core/templates/partials/form_login.html
@@ -25,9 +25,6 @@
- {% if show_password_forget_notice %}
- {% trans 'Forgot password?' %}
- {% endif %}
{% else %}