add password reset

This commit is contained in:
Trent Palmer 2021-03-06 01:43:07 -08:00
parent f9f8bf13ac
commit 5d6ae12550
7 changed files with 117 additions and 1 deletions

View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}
{% include "base_navbar.html" %}
{% include "base_heading.html" %}
<div class="d-flex flex-column align-items-center">
<p class="text-justify px-3">{% translate 'Weve emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly.' %}</p>
<p class="text-justify px-3">{% translate 'If you dont receive an email, please make sure youve entered the address you registered with, and check your spam folder.' %}</p>
</div>
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}
{% include "base_navbar.html" %}
{% include "base_heading.html" %}
<p class="text-center">{% translate "Your password has been set." %}</p>
<p class="text-center">{% translate "You may go ahead and log in now." %}</p>
<p class="text-center"><a href="{{ login_url }}">{% translate 'Log in' %}</a></p>
{% endblock %}

View File

@ -0,0 +1,14 @@
{% load i18n %}{% autoescape off %}
{% blocktranslate %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktranslate %}
{% translate "Please go to the following page and choose a new password:" %}
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url 'accounts:password_reset_confirm' uidb64=uid token=token %}
{% endblock %}
{% translate 'Your username, in case youve forgotten:' %} {{ user.get_username }}
{% translate "Thanks for using our site!" %}
{% blocktranslate %}The {{ site_name }} team{% endblocktranslate %}
{% endautoescape %}

View File

@ -0,0 +1,40 @@
{% extends "base.html" %}
{% load i18n static %}
{% load crispy_forms_tags %}
{% block content %}
{% include "base_navbar.html" %}
{% if validlink %}
<div class="container">
<div class="row justify-content-center my-2 mx-0">
<h1 class="text-center">Enter New Password</h1>
</div>
</div>
<div class="container">
<div class="d-flex flex-column offset-sm-3 col-sm-6 col-xs-12 px-0">
<form method="POST">
{% csrf_token %}
{{ form | crispy }}
<div class="mt-3">
<input type="submit" class="btn btn-dark btn-lg" value="Change My Password">
</div>
</form>
</div>
</div>
{% else %}
<div class="container">
<div class="row justify-content-center my-2 mx-0">
<h1 class="text-center">Error</h1>
</div>
</div>
<p class="text-center">{% translate "The password reset link was invalid, possibly because it has already been used. Please request a new password reset." %}</p>
{% endif %}
{% endblock %}

View File

@ -1,4 +1,5 @@
from django.urls import path
from django.urls import path, reverse_lazy
from django.contrib.auth import views as av
from .enable_totp import enable_totp, disable_totp
from .login import log_in, two_factor_input
from . import views
@ -13,4 +14,24 @@ urlpatterns = [
path('enable-totp/', enable_totp, name='enable_totp'),
path('disable-totp/', disable_totp, name='disable_totp'),
path('two-factor-input/', two_factor_input, name='two_factor_input'),
path('reset-password/', av.PasswordResetView.as_view(
template_name='base_form.html',
email_template_name="accounts/password_reset_email.html",
success_url=reverse_lazy('accounts:password_reset_done')),
name='password_reset'),
path(
'reset-password-sent/',
av.PasswordResetDoneView.as_view(template_name='accounts/password_change_done.html'),
name="password_reset_done"),
path('reset/<uidb64>/<token>/', av.PasswordResetConfirmView.as_view(
template_name='accounts/set_password_form.html',
success_url=reverse_lazy('accounts:password_reset_complete')),
name="password_reset_confirm"),
path('reset-password-complete/', av.PasswordResetCompleteView.as_view(
template_name='accounts/password_reset_complete.html'),
name="password_reset_complete"),
]

View File

@ -7,6 +7,7 @@
{% url 'accounts:edit_profile' as edit_profile_url %}
{% url 'accounts:password_change' as password_change_url %}
{% url 'audio:new_feed' as new_feed_url %}
{% url 'accounts:password_reset' as password_reset_url %}
{% if request.path == login_url %}
{% firstof 'Login' as submit %}
@ -16,6 +17,8 @@
{% firstof 'Update' as submit %}
{% elif request.path == new_feed_url %}
{% firstof 'Submit' as submit %}
{% elif request.path == password_reset_url %}
{% firstof 'Reset Password' as submit %}
{% endif %}
{% include "base_navbar.html" %}
@ -49,6 +52,9 @@
</div>
</div>
{% endif %}
{% if request.path == login_url %}
<p>Forgot Password? <a href="{% url 'accounts:password_reset' %}">Reset Password</a></p>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -9,6 +9,9 @@
{% url 'audio:new_feed' as new_feed_url %}
{% url 'audio:feeds' as feeds_url %}
{% url 'audio:home' as home_url %}
{% url 'accounts:password_reset' as password_reset_url %}
{% url 'accounts:password_reset_done' as password_reset_done_url %}
{% url 'accounts:password_reset_complete' as password_reset_complete_url %}
{% if request.path == login_url %}
Login?
@ -26,6 +29,12 @@
Feeds
{% elif request.path == home_url %}
Home
{% elif request.path == password_reset_url %}
Reset Password?
{% elif request.path == password_reset_done_url %}
Password Reset Sent
{% elif request.path == password_reset_complete_url %}
Password Reset Complete
{% endif %}
{{ heading }}