Skip to content

Commit

Permalink
Reset Password Functionality in #94
Browse files Browse the repository at this point in the history
  • Loading branch information
kunfang98927 committed Nov 9, 2023
1 parent 59df9c5 commit 97a23e8
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load static %}

{% block title %}
Login
Change Password
{% endblock %}

{% block css_files %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% block content %}
<div class="container">
<div class="row">
<div class="mr-3 p-4 col-md-6">
<div class="mr-3 p-4 col-md-8">
{% if messages %}
<div class="alert alert-success alert-dismissible">
{% for message in messages %}
Expand Down Expand Up @@ -40,7 +40,10 @@ <h5><strong>Login for Contributors</strong></h5>
{{ form.password }}
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
<p class="mt-2">
<a href="{% url 'main:reset_password' %}">Forgot your password?</a>
</p>
</form>
</div>
<div class="col-md mt-4 create-account-link">
<p>Don't have an account?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends "base.html" %}
{% load static %}

{% block title %}
Reset Password
{% endblock %}

{% block css_files %}
<link rel="stylesheet" type="text/css" href="{% static 'main/css/login.css' %}">
{% endblock %}

{% block content %}
<div class="container">
<div class="row">
<div class="mr-3 p-4 col-md-12">
{% if messages %}
<div class="alert alert-success alert-dismissible">
{% for message in messages %}
{{ message }}
{% endfor %}
</div>
{% endif %}
{% if form.errors %}
<div class="alert alert-danger alert-dismissible">
{% for field, error in form.errors.items %}
{{ error }}
{% endfor %}
</div>
{% endif %}
<div class="col-md mt-4 login-form" id="login">
<h5><strong>Reset Password</strong></h5>
<p class="mt-4">Forgotten your password? Enter your email address below, and we'll email instructions for setting a new one.</p>
<form method="post">
{% csrf_token %}
<div class="mt-4 mb-4">
<label for="exampleInputEmail" class="form-label">Email Address</label>
{{ form.email }}
</div>
<button type="submit" class="btn btn-primary">Send Password Reset Email</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base.html" %}
{% load static %}

{% block title %}
Reset Password
{% endblock %}

{% block css_files %}
<link rel="stylesheet" type="text/css" href="{% static 'main/css/login.css' %}">
{% endblock %}

{% block content %}
<div class="container">
<div class="row">
<div class="mr-3 p-4 col-md-12">
<div class="col-md mt-4 login-form" id="login">
<h5><strong>Password Reset Complete</strong></h5>
<p class="mt-4">Your password has been successfully reset. You can now <a href="{% url 'main:login' %}">log in</a> with your new password.</p>
</div>
</div>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "base.html" %}
{% load static %}

{% block title %}
Reset Password
{% endblock %}

{% block css_files %}
<link rel="stylesheet" type="text/css" href="{% static 'main/css/login.css' %}">
{% endblock %}

{% block content %}
<div class="container">
<div class="row">
<div class="mr-3 p-4 col-md-12">
<div class="col-md mt-4 login-form" id="login">
<h5><strong>Set New Password</strong></h5>
<form class="mt-4" method="post">
{% csrf_token %}
{{ form.new_password1.label_tag }}
{{ form.new_password1 }}
{{ form.new_password2.label_tag }}
{{ form.new_password2 }}
<button type="submit" class="btn btn-primary">Change Password</button>
</form>
</div>
</div>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Please click the following link to reset your password:

{% autoescape off %}
{{ protocol }}://{{ domain }}{% url 'main:reset_password_confirm' uidb64=uid token=token %}
{% endautoescape %}

If you didn't request a password reset, please ignore this message.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "base.html" %}
{% load static %}

{% block title %}
Reset Password
{% endblock %}

{% block css_files %}
<link rel="stylesheet" type="text/css" href="{% static 'main/css/login.css' %}">
{% endblock %}

{% block content %}
<div class="container">
<div class="row">
<div class="mr-3 p-4 col-md-12">
<div class="col-md mt-4 login-form" id="login">
<h5><strong>Password Reset Email Sent</strong></h5>
<p class="mt-4">We've sent you an email with instructions to reset your password. Please check your inbox.</p>
</div>
</div>
</div>
</div>
{% endblock %}
31 changes: 31 additions & 0 deletions web-app/django/VIM/apps/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,35 @@
),
name="login",
),
path(
"reset-password/",
auth_views.PasswordResetView.as_view(
template_name="registration/reset_password.html",
email_template_name="registration/reset_password_email.html",
success_url="/reset-password-sent/",
),
name="reset_password",
),
path(
"reset-password-sent/",
auth_views.PasswordResetDoneView.as_view(
template_name="registration/reset_password_sent.html",
),
name="reset_password_done",
),
path(
"reset/<uidb64>/<token>",
auth_views.PasswordResetConfirmView.as_view(
template_name="registration/reset_password_confirm.html",
success_url="/reset-password-complete/",
),
name="reset_password_confirm",
),
path(
"reset-password-complete/",
auth_views.PasswordResetCompleteView.as_view(
template_name="registration/reset_password_complete.html",
),
name="reset_password_complete",
),
]
10 changes: 10 additions & 0 deletions web-app/django/VIM/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "email-smtp.us-west-2.amazonaws.com"
EMAIL_PORT = 587
EMAIL_HOST_USER = os.getenv("AWS_EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("AWS_EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = True

# Copied from CantusDB, will need to change
DEFAULT_FROM_EMAIL = "[email protected]"

# DEPLOYMENT SETTINGS

CSRF_COOKIE_SECURE = IS_PRODUCTION
Expand Down

0 comments on commit 97a23e8

Please sign in to comment.