-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create back-office account management templates #4380
- Loading branch information
Showing
11 changed files
with
653 additions
and
95 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,99 @@ | ||
__copyright__ = "Copyright 2024 Birkbeck, University of London" | ||
__author__ = "Open Library of Humanities" | ||
__license__ = "AGPL v3" | ||
__maintainer__ = "Open Library of Humanities" | ||
|
||
from mock import patch | ||
from uuid import uuid4 | ||
|
||
from django.test import Client, TestCase, override_settings | ||
|
||
from utils.testing import helpers | ||
|
||
from core import models as core_models | ||
|
||
|
||
class CoreViewTestsWithData(TestCase): | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
cls.press = helpers.create_press() | ||
cls.journal_one, cls.journal_two = helpers.create_journals() | ||
helpers.create_roles(['author']) | ||
cls.user_email = 'sukv8golcvwervs0y7e5@example.org' | ||
cls.user_password = 'xUMXW1oXn2l8L26Kixi2' | ||
cls.user = core_models.Account.objects.create_user( | ||
cls.user_email, | ||
password=cls.user_password, | ||
) | ||
cls.user.confirmation_code = uuid4() | ||
cls.user.is_active = True | ||
cls.user_orcid = 'https://orcid.org/0000-0001-2345-6789' | ||
cls.user.orcid = cls.user_orcid | ||
cls.orcid_token_uuid = uuid4() | ||
cls.orcid_token = core_models.OrcidToken.objects.create( | ||
token=cls.orcid_token_uuid, | ||
orcid=cls.user_orcid, | ||
) | ||
cls.reset_token_uuid = uuid4() | ||
cls.reset_token = core_models.PasswordResetToken.objects.create( | ||
account=cls.user, | ||
token=cls.reset_token_uuid, | ||
) | ||
cls.user.save() | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
|
||
|
||
class AccountManagementTemplateTests(CoreViewTestsWithData): | ||
|
||
def test_user_login(self): | ||
url = '/login/' | ||
data = {} | ||
template = 'admin/core/accounts/login.html' | ||
response = self.client.get(url, data) | ||
self.assertTemplateUsed(response, template) | ||
|
||
def test_get_reset_token(self): | ||
url = '/reset/step/1/' | ||
data = {} | ||
template = 'admin/core/accounts/get_reset_token.html' | ||
response = self.client.get(url, data) | ||
self.assertTemplateUsed(response, template) | ||
|
||
def test_reset_password(self): | ||
url = f'/reset/step/2/{self.reset_token_uuid}/' | ||
data = {} | ||
template = 'admin/core/accounts/reset_password.html' | ||
response = self.client.get(url, data) | ||
self.assertTemplateUsed(response, template) | ||
|
||
def test_register(self): | ||
url = '/register/step/1/' | ||
data = {} | ||
template = 'admin/core/accounts/register.html' | ||
response = self.client.get(url, data) | ||
self.assertTemplateUsed(response, template) | ||
|
||
def test_orcid_registration(self): | ||
url = f'/register/step/orcid/{self.orcid_token_uuid}/' | ||
data = {} | ||
template = 'admin/core/accounts/orcid_registration.html' | ||
response = self.client.get(url, data) | ||
self.assertTemplateUsed(response, template) | ||
|
||
def test_activate_account(self): | ||
url = f'/register/step/2/{self.user.confirmation_code}/' | ||
data = {} | ||
template = 'admin/core/accounts/activate_account.html' | ||
response = self.client.get(url, data) | ||
self.assertTemplateUsed(response, template) | ||
|
||
def test_edit_profile(self): | ||
self.client.login(username=self.user_email, password=self.user_password) | ||
url = '/profile/' | ||
data = {} | ||
template = 'admin/core/accounts/edit_profile.html' | ||
response = self.client.get(url, data) | ||
self.assertTemplateUsed(response, template) |
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
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,40 @@ | ||
{% extends "admin/core/small_form.html" %} | ||
{% load i18n foundation %} | ||
|
||
{% block contextual_title %} | ||
{% trans "Activate Account" %} | ||
{% endblock contextual_title %} | ||
|
||
{% block breadcrumbs %} | ||
{{ block.super }} | ||
<li>{% trans "Activate Account" %}</li> | ||
{% endblock breadcrumbs %} | ||
|
||
{% block form_content %} | ||
{% if account %} | ||
<h2 class="text-center"> | ||
{% trans "Activate Account" %} | ||
</h2> | ||
{% include "admin/elements/forms/accessible_messages.html" with form=form %} | ||
<p>{% blocktrans %} | ||
You can complete the activation process by clicking the button | ||
below. | ||
{% endblocktrans %}</p> | ||
<button class="button secondary expanded" name="activate"> | ||
{% trans "Activate Account" %} | ||
</button> | ||
{% else %} | ||
<h2 class="text-center"> | ||
{% trans "No account to activate" %} | ||
</h2> | ||
<p>{% blocktrans %} | ||
Sorry, we could not find an account to activate, or your account is active | ||
already. You can check if it is active by attempting to log in. | ||
{% endblocktrans %}</p> | ||
<div> | ||
<a class="button secondary expanded" href="{% url 'core_login' %}"> | ||
{% trans "Log in" %} | ||
</a> | ||
</div> | ||
{% endif %} | ||
{% endblock form_content %} |
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,140 @@ | ||
{% extends "admin/core/large_form.html" %} | ||
{% load i18n foundation static %} | ||
|
||
{% block css %} | ||
<link type='text/css' href="{% static " common/css/jq-ui.css" %}" rel="stylesheet"> | ||
{% endblock %} | ||
|
||
{% block contextual_title %} | ||
{% trans "Edit Profile" %} | ||
{% endblock contextual_title %} | ||
|
||
{% block body %} | ||
<div class="grid place-content-center gap-0"> | ||
<h2 class="text-center"> | ||
{% trans "Edit Profile" %} | ||
</h2> | ||
{% include "admin/elements/forms/accessible_messages.html" with form=form %} | ||
<div class="max-w-56"> | ||
<section class="card padding-block-2 padding-inline-2"> | ||
<h3>{% trans "Change Your Email Address" %}</h3> | ||
{% blocktrans %} | ||
<p>If you want to change your email address you may do so below, | ||
however, you will be logged out and your | ||
account will be marked as inactive until you follow the | ||
instructions in the verification email. <strong>Note: </strong> | ||
Changing your email address will also change your username as these | ||
are one and the same.</p> | ||
{% endblocktrans %} | ||
<p><strong>{% trans 'Current Email Address' %}:</strong> | ||
{{ request.user.email }}</p> | ||
<form method="POST"> | ||
{% csrf_token %} | ||
<div class="flex wrap column-gap-2"> | ||
<div> | ||
<label for="email_address"> | ||
<strong>{% trans 'New Email Address' %}</strong> | ||
<span aria-hidden="true">*</span> | ||
</label> | ||
<input type="email" name="email_address" required="true"> | ||
</div> | ||
</div> | ||
<button type="submit" name="email" class="button secondary"> | ||
{% trans "Update Email Address" %} | ||
</button> | ||
</form> | ||
{% include "admin/elements/forms/denotes_required.html" %} | ||
</section> | ||
{% if request.journal and send_reader_notifications %} | ||
<section class="card padding-block-2 padding-inline-2"> | ||
<h3>{% trans "Register for Article Notifications" %}</h3> | ||
<form method="POST"> | ||
<p>{% blocktrans %} | ||
Use the button below to register to receive notifications of new articles | ||
published in this journal. | ||
{% endblocktrans %}</p> | ||
{% csrf_token %} | ||
{% if reader %} | ||
<button name="unsubscribe" class="button secondary"> | ||
{% trans "Unsubscribe from Article Notifications" %} | ||
</button> | ||
{% else %} | ||
<button name="subscribe" class="button secondary"> | ||
{% trans "Subscribe to Article Notifications" %} | ||
</button> | ||
{% endif %} | ||
</form> | ||
</section> | ||
{% endif %} | ||
<section class="card padding-block-2 padding-inline-2"> | ||
<h3>{% trans "Update Password" %}</h3> | ||
<p>{% blocktrans %} | ||
You can update your password by entering your existing | ||
password plus your new password. | ||
{% endblocktrans %}</p> | ||
<form method="POST"> | ||
{% csrf_token %} | ||
<div class="flex wrap column-gap-2"> | ||
<div> | ||
<label for="current_password"> | ||
<strong>{% trans "Current Password" %}</strong> | ||
<span aria-hidden="true">*</span> | ||
</label> | ||
<input type="password" name="current_password" required="true"> | ||
</div> | ||
<div> | ||
<label for="new_password_one"> | ||
<strong>{% trans "New Password" %}</strong> | ||
<span aria-hidden="true">*</span> | ||
</label> | ||
<input type="password" name="new_password_one" required="true"> | ||
</div> | ||
<div> | ||
<label for="new_password_two"> | ||
<strong>{% trans "Enter Password Again" %}</strong> | ||
<span aria-hidden="true">*</span> | ||
</label> | ||
<input type="password" name="new_password_two" required="true"> | ||
</div> | ||
</div> | ||
<button | ||
type="submit" | ||
name="change_password" | ||
class="button secondary"> | ||
{% trans "Update Password" %} | ||
</button> | ||
</form> | ||
{% include "admin/elements/forms/denotes_required.html" %} | ||
</section> | ||
<section class="card padding-block-2 padding-inline-2"> | ||
<h3>{% trans 'Profile Details' %}</h3> | ||
<form method="POST" enctype="multipart/form-data"> | ||
{% csrf_token %} | ||
{% include "admin/elements/accounts/user_form.html" %} | ||
<div> | ||
<button | ||
type="submit" | ||
name="edit_profile" | ||
class="button secondary"> | ||
<span class="fa fa-save"></span> | ||
{% trans "Save" %} | ||
</button> | ||
</div> | ||
{% include "admin/elements/forms/denotes_required.html" %} | ||
</form> | ||
</section> | ||
</div> | ||
</div> | ||
{% endblock body %} | ||
|
||
{% block js %} | ||
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css"> | ||
<script type="text/javascript" src="{% static "common/js/jq-ui.min.js" %}"></script> | ||
<script src="{% static "common/js/tagit.js" %}"></script> | ||
<script type="text/javascript"> | ||
$(document).ready(function() { | ||
$("#id_interests").tagit( | ||
{allowSpaces: true}); | ||
}); | ||
</script> | ||
{% 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,30 @@ | ||
{% extends "admin/core/small_form.html" %} | ||
{% load orcid fqdn i18n foundation %} | ||
|
||
{% block contextual_title %} | ||
{% trans "Reset password" %} | ||
{% endblock contextual_title %} | ||
|
||
{% block breadcrumbs %} | ||
{{ block.super }} | ||
<li>{% trans "Reset password" %}</li> | ||
{% endblock breadcrumbs %} | ||
|
||
{% block form_content %} | ||
<h2 class="text-center"> | ||
{% trans "Reset password" %} | ||
</h2> | ||
{% include "admin/elements/forms/accessible_messages.html" with form=form %} | ||
<p> | ||
{% blocktrans %} | ||
Enter your email address and then follow the link sent to you by email. | ||
{% endblocktrans %} | ||
</p> | ||
{% include "admin/elements/forms/field.html" with field=form.email_address %} | ||
<div> | ||
<button type="submit" class="button secondary expanded"> | ||
{% trans "Request link" %} | ||
</button> | ||
</div> | ||
{% include "admin/elements/forms/denotes_required.html" %} | ||
{% endblock form_content %} |
Oops, something went wrong.