-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace OID with Django authentication system
Why these changes are being introduced: * OpenID Connect (OIDC) is no longer functional and will not be supported by ITS in the near future, and this prevents Solenoid from working. Replacing OIDC with Django's built-in authentication system will return the app to a functioning state until we have a better understanding of how to apply authentication with Touchstone SAML. How this addresses that need: * Create a new application for authorization (accounts) * Create a templates/accounts directory to store all templates for authorization * Create a accounts/urls.py for creating/managing different views (pages) for authorization * Add 'accounts' app to solenoid.settings.base.py Note(s): 1. The structure of 'urls.py' and the templates for authorization are essentially the default files provided by Django with minor changes. For instance, the urls.py is pretty much modeled from: https://github.com/django/django/blob/main/django/contrib/auth/urls.py. 2. The important changes to solenoid.settings.base.py (i.e., the Django configs) are essentially: (a) the addition of the 'accounts' app to SOLENOID_APPS, (b) removing references to the MITOAuth2 authentication backend and only using LOGIN_REDIRECT_URL instead, and (c) commenting out the 'WhiteNoiseMiddleWare' setting in line 76 (I'm not sure what it does, but when I compared the settings in base.py with that of the default settings, this was the only middleware that wasn't included). The other changes are formatting changes related to "Black" (i.e., line lengths and quotation marks) Side effects of this change: * Relevant ticket(s): * TBD
- Loading branch information
1 parent
5a0a773
commit 6c053e9
Showing
11 changed files
with
284 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
|
||
{% if form.errors %} | ||
<p>Your username and password didn't match. Please try again.</p> | ||
{% endif %} | ||
|
||
{% if next %} | ||
{% if user.is_authenticated %} | ||
<p>Your account doesn't have access to this page. To proceed, | ||
please login with an account that has access.</p> | ||
{% else %} | ||
<p>Please login to see this page.</p> | ||
{% endif %} | ||
{% endif %} | ||
|
||
<form method="post" action="{% url 'accounts:login' %}"> | ||
{% csrf_token %} | ||
<table> | ||
<tr> | ||
<td>{{ form.username.label_tag }}</td> | ||
<td>{{ form.username }}</td> | ||
</tr> | ||
<tr> | ||
<td>{{ form.password.label_tag }}</td> | ||
<td>{{ form.password }}</td> | ||
</tr> | ||
</table> | ||
<input type="submit" value="Login"> | ||
<input type="hidden" name="next" value="{{ next }}"> | ||
</form> | ||
|
||
{# Assumes you setup the password_reset view in your URLconf #} | ||
<p><a href="{% url 'accounts:password_reset' %}">Need help signing in?</a></p> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<p>You have successfully logged out. Have a nice day! </p> | ||
<a href="{% url 'accounts:login'%}">Return to login page.</a> | ||
{% endblock %} |
6 changes: 6 additions & 0 deletions
6
solenoid/accounts/templates/accounts/password_reset_complete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<p>The password has been changed.</h1> | ||
<p><a href="{% url 'accounts:login' %}">Return to login page.</a></p> | ||
{% endblock %} |
29 changes: 29 additions & 0 deletions
29
solenoid/accounts/templates/accounts/password_reset_confirm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
{% if validlink %} | ||
<p>Please enter (and confirm) your new password.</p> | ||
<form action="" method="post"> | ||
{% csrf_token %} | ||
<table> | ||
<tr> | ||
<td>{{ form.new_password1.errors }} | ||
<label for="id_new_password1">New password:</label></td> | ||
<td>{{ form.new_password1 }}</td> | ||
</tr> | ||
<tr> | ||
<td>{{ form.new_password2.errors }} | ||
<label for="id_new_password2">Confirm password:</label></td> | ||
<td>{{ form.new_password2 }}</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td><input type="submit" value="Change my password"></td> | ||
</tr> | ||
</table> | ||
</form> | ||
{% else %} | ||
<h1>Password reset failed</h1> | ||
<p>The password reset link was invalid, possibly because it has already been used. Please request a new password reset.</p> | ||
{% endif %} | ||
{% endblock %} |
5 changes: 5 additions & 0 deletions
5
solenoid/accounts/templates/accounts/password_reset_done.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<p>We've emailed you instructions for setting your password. If they haven't arrived in a few minutes, check your spam folder.</p> | ||
{% endblock %} |
2 changes: 2 additions & 0 deletions
2
solenoid/accounts/templates/accounts/password_reset_email.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Someone asked for password reset for email {{ email }}. Follow the link below: | ||
{{ protocol }}://{{ domain }}{% url 'accounts:password_reset_confirm' uidb64=uid token=token %} |
13 changes: 13 additions & 0 deletions
13
solenoid/accounts/templates/accounts/password_reset_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<form action="" method="post"> | ||
{% csrf_token %} | ||
{% if form.email.errors %} | ||
{{ form.email.errors }} | ||
{% endif %} | ||
<p> Enter your email address below to receive instructions for resetting your password </p> | ||
<p>{{ form.as_p }}</p> | ||
<input type="submit" class="btn btn-default btn-lg" value="Reset password"> | ||
</form> | ||
{% endblock %} |
3 changes: 3 additions & 0 deletions
3
solenoid/accounts/templates/accounts/password_reset_subject.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% load i18n %}{% autoescape off %} | ||
{% blocktrans %}Password reset on {{ site_name }}{% endblocktrans %} | ||
{% endautoescape %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from django.urls import path, re_path, reverse_lazy | ||
from django.contrib.auth.views import * | ||
from django.views.generic import TemplateView | ||
|
||
app_name = "accounts" | ||
|
||
urlpatterns = [ | ||
path( | ||
"login/", | ||
LoginView.as_view(template_name="accounts/login.html"), | ||
name="login", | ||
), | ||
path( | ||
"logout/", | ||
LogoutView.as_view(template_name="accounts/logout.html"), | ||
name="logout", | ||
), | ||
path( | ||
"password_reset/", | ||
PasswordResetView.as_view( | ||
email_template_name="accounts/password_reset_email.html", | ||
subject_template_name="accounts/password_reset_subject.txt", | ||
template_name="accounts/password_reset_form.html", | ||
success_url=reverse_lazy("accounts:password_reset_done"), | ||
), | ||
name="password_reset", | ||
), | ||
path( | ||
"password_reset/done/", | ||
PasswordResetDoneView.as_view(template_name="accounts/password_reset_done.html"), | ||
name="password_reset_done", | ||
), | ||
path( | ||
"reset/<uidb64>/<token>/", | ||
PasswordResetConfirmView.as_view( | ||
template_name="accounts/password_reset_confirm.html", | ||
success_url=reverse_lazy("accounts:password_reset_complete"), | ||
), | ||
name="password_reset_confirm", | ||
), | ||
path( | ||
"reset/done/", | ||
PasswordResetCompleteView.as_view( | ||
template_name="accounts/password_reset_complete.html" | ||
), | ||
name="password_reset_complete", | ||
), | ||
] |
Oops, something went wrong.