diff --git a/corpus/accounts/urls.py b/corpus/accounts/urls.py index 6c291ade..46a7fe1d 100644 --- a/corpus/accounts/urls.py +++ b/corpus/accounts/urls.py @@ -1,3 +1,7 @@ +from django.contrib.auth.views import PasswordResetCompleteView +from django.contrib.auth.views import PasswordResetConfirmView +from django.contrib.auth.views import PasswordResetDoneView +from django.contrib.auth.views import PasswordResetView from django.urls import path from .views import signin @@ -8,4 +12,16 @@ path("signup/", signup, name="accounts_signup"), path("login/", signin, name="accounts_signin"), path("logout/", signout, name="accounts_signout"), + path("reset/", PasswordResetView.as_view(), name="password_reset"), + path("reset/done/", PasswordResetDoneView.as_view(), name="password_reset_done"), + path( + "reset/confirm///", + PasswordResetConfirmView.as_view(), + name="password_reset_confirm", + ), + path( + "reset/complete/", + PasswordResetCompleteView.as_view(), + name="password_reset_complete", + ), ] diff --git a/corpus/corpus/settings.py b/corpus/corpus/settings.py index f3c71d3f..09d0c444 100644 --- a/corpus/corpus/settings.py +++ b/corpus/corpus/settings.py @@ -167,6 +167,10 @@ AUTHENTICATION_BACKENDS = [ "accounts.backend.CorpusAuthBackend", ] + +# Reset Timeout in seconds. 1 day +PASSWORD_RESET_TIMEOUT = 86400 + LOGIN_URL = "/accounts/login" LOGIN_REDIRECT_URL = "/" LOGOUT_URL = "" @@ -175,7 +179,9 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # Email Settings -EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" +EMAIL_PROTOCOL = os.getenv("EMAIL_PROTOCOL", "console") + +EMAIL_BACKEND = f"django.core.mail.backends.{EMAIL_PROTOCOL}.EmailBackend" EMAIL_HOST = os.environ.get("EMAIL_HOST", "smtp.gmail.com") EMAIL_HOST_USER = os.environ.get("EMAIL_HOST_USER", "corpusieeenitk@gmail.com") EMAIL_HOST_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD", "gmailapppassword") diff --git a/corpus/templates/accounts/login.html b/corpus/templates/accounts/login.html index 77d943b7..7f93f836 100644 --- a/corpus/templates/accounts/login.html +++ b/corpus/templates/accounts/login.html @@ -47,6 +47,10 @@

Login

{% endif %} +
diff --git a/corpus/templates/registration/password_reset_complete.html b/corpus/templates/registration/password_reset_complete.html new file mode 100644 index 00000000..78b2a82d --- /dev/null +++ b/corpus/templates/registration/password_reset_complete.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} + +{% block title %} + Complete! | Reset Password +{% endblock %} + +{% block content %} +
+
+

Complete!

+

+ Your password has been reset. + Please continue to + + login + + to access your account. +

+
+
+{% endblock %} diff --git a/corpus/templates/registration/password_reset_confirm.html b/corpus/templates/registration/password_reset_confirm.html new file mode 100644 index 00000000..ac05a8e0 --- /dev/null +++ b/corpus/templates/registration/password_reset_confirm.html @@ -0,0 +1,60 @@ +{% extends 'base.html' %} + +{% block title %} + Reset Password +{% endblock %} + +{% block content %} +
+
+ {% if validlink %} +

Reset Password

+
+ {% csrf_token %} + + {% if form.non_field_errors %} + {% for error in form.non_field_errors %} + + {% endfor %} + {% endif %} + +
+ + {{ form.new_password1 }} + {% if form.new_password1.errors %} +
+ +
+ {% endif %} +
+ +
+ + {{ form.new_password2 }} + {% if form.new_password2.errors %} +
+ +
+ {% endif %} +
+ +
+ +
+
+ {% else %} +

Invalid Link

+

+ The password reset link was invalid, possibly because it has already been used. + Please request a new password reset link. +

+ {% endif %} +
+
+{% endblock %} diff --git a/corpus/templates/registration/password_reset_done.html b/corpus/templates/registration/password_reset_done.html new file mode 100644 index 00000000..ecf02b53 --- /dev/null +++ b/corpus/templates/registration/password_reset_done.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} + +{% block title %} + Done! | Reset Password +{% endblock %} + +{% block content %} +
+
+

Reset Password

+

+ We've emailed you instructions for setting your password, if an account exists with the email you + entered. You should receive them shortly. The reset link is valid for 1 day. +

+

+ If you don't receive an email, please make sure you've entered the address you registered with, and + check your spam folder. +

+
+
+{% endblock %} diff --git a/corpus/templates/registration/password_reset_email.html b/corpus/templates/registration/password_reset_email.html new file mode 100644 index 00000000..d682ebf4 --- /dev/null +++ b/corpus/templates/registration/password_reset_email.html @@ -0,0 +1,31 @@ +{% extends 'emails/base.html' %} + +{% block title %} + Reset Password | Corpus | IEEE NITK +{% endblock %} + +{% block content %} +{% autoescape off %} +

+ To initiate the password reset process for your {{ user.get_username }} Corpus Account, + click the link below: +

+ +

+ {{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} +

+ +

+ If clicking the link above doesn't work, please copy and paste the URL in a new browser window instead. +

+

+ The link will be accessible for the next 1 day. +

+ +

+ Sincerely, +
+ IEEE NITK +

+{% endautoescape %} +{% endblock %} diff --git a/corpus/templates/registration/password_reset_form.html b/corpus/templates/registration/password_reset_form.html new file mode 100644 index 00000000..1be33f26 --- /dev/null +++ b/corpus/templates/registration/password_reset_form.html @@ -0,0 +1,41 @@ +{% extends 'base.html' %} + +{% block title %} + Reset Password +{% endblock %} + +{% block content %} +
+
+

Reset Password

+ +
+ {% csrf_token %} + + {% if form.non_field_errors %} + {% for error in form.non_field_errors %} + + {% endfor %} + {% endif %} + +
+ + {{ form.email }} + {% if form.email.errors %} +
+ +
+ {% endif %} +
+ +
+ +
+
+
+
+{% endblock %} diff --git a/corpus/templates/registration/password_reset_subject.txt b/corpus/templates/registration/password_reset_subject.txt new file mode 100644 index 00000000..4d344640 --- /dev/null +++ b/corpus/templates/registration/password_reset_subject.txt @@ -0,0 +1 @@ +Reset Password | Corpus | IEEE NITK diff --git a/docker-compose.yml b/docker-compose.yml index d24d0810..e20823bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,6 +50,7 @@ services: - .env environment: - ENVIRONMENT=DEVELOPMENT + - EMAIL_PROTOCOL=console jstoolchain: build: diff --git a/prod-docker-compose.yml b/prod-docker-compose.yml index a31c47cc..281ca671 100644 --- a/prod-docker-compose.yml +++ b/prod-docker-compose.yml @@ -49,6 +49,7 @@ services: - .env environment: - ENVIRONMENT=PRODUCTION + - EMAIL_PROTOCOL=smtp nginx: build: nginx