mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-25 18:43:49 +02:00
working code
This commit is contained in:
parent
ff7a745ffa
commit
1445bba954
4 changed files with 83 additions and 67 deletions
|
@ -1301,6 +1301,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* An IIFE that displays confirmation modal on the user profile page
|
||||
*/
|
||||
(function userProfileListener() {
|
||||
|
||||
const showConfirmationModalTrigger = document.querySelector('.show-confirmation-modal');
|
||||
if (showConfirmationModalTrigger) {
|
||||
showConfirmationModalTrigger.click();
|
||||
}
|
||||
}
|
||||
)();
|
||||
|
||||
/**
|
||||
* An IIFE that hooks up the edit buttons on the finish-user-setup page
|
||||
*/
|
||||
|
|
|
@ -44,10 +44,12 @@ class CheckUserProfileMiddleware:
|
|||
self.regular_excluded_pages = [
|
||||
self.setup_page,
|
||||
self.logout_page,
|
||||
'/admin',
|
||||
]
|
||||
self.other_excluded_pages = [
|
||||
self.profile_page,
|
||||
self.logout_page,
|
||||
'/admin',
|
||||
]
|
||||
|
||||
def __call__(self, request):
|
||||
|
@ -92,7 +94,7 @@ class CheckUserProfileMiddleware:
|
|||
custom_redirect = "domain-request:" if request.path == "/request/" else None
|
||||
|
||||
# Don't redirect on excluded pages (such as the setup page itself)
|
||||
if not any(request.path.startswith(page) for page in self.excluded_pages):
|
||||
if not any(request.path.startswith(page) for page in self.regular_excluded_pages):
|
||||
|
||||
# Preserve the original query parameters, and coerce them into a dict
|
||||
query_params = parse_qs(request.META["QUERY_STRING"])
|
||||
|
@ -114,7 +116,7 @@ class CheckUserProfileMiddleware:
|
|||
"""
|
||||
|
||||
# Don't redirect on excluded pages (such as the setup page itself)
|
||||
if not any(request.path.startswith(page) for page in self.excluded_pages):
|
||||
if not any(request.path.startswith(page) for page in self.other_excluded_pages):
|
||||
return HttpResponseRedirect(self.profile_page)
|
||||
else:
|
||||
# Process the view as normal
|
||||
|
|
|
@ -5,6 +5,11 @@ Edit your User Profile |
|
|||
{% endblock title %}
|
||||
{% load static url_helpers %}
|
||||
|
||||
{# Disable the redirect #}
|
||||
{% block logo %}
|
||||
{% include "includes/gov_extended_logo.html" with logo_clickable=user_finished_setup %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<main id="main-content" class="grid-container">
|
||||
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
|
||||
|
@ -37,67 +42,49 @@ Edit your User Profile |
|
|||
{% endif %}
|
||||
|
||||
{% if show_confirmation_modal %}
|
||||
<div class="usa-modal__content">
|
||||
<div class="usa-modal__main">
|
||||
<h2 class="usa-modal__heading" id="modal-1-heading">
|
||||
{{ modal_heading }}
|
||||
{% if heading_value is not None %}
|
||||
{# Add a breakpoint #}
|
||||
<div aria-hidden="true"></div>
|
||||
{{ heading_value }}
|
||||
{% endif %}
|
||||
</h2>
|
||||
<div class="usa-prose">
|
||||
<p id="modal-1-description">
|
||||
{{ modal_description }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="usa-modal__footer">
|
||||
<ul class="usa-button-group">
|
||||
{% if not_form %}
|
||||
<li class="usa-button-group__item">
|
||||
{{ modal_button }}
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="usa-button-group__item">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ modal_button }}
|
||||
</form>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="usa-button-group__item">
|
||||
{% comment %} The cancel button the DS form actually triggers a context change in the view,
|
||||
in addition to being a close modal hook {% endcomment %}
|
||||
{% if cancel_button_resets_ds_form %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<button
|
||||
type="submit"
|
||||
class="usa-button usa-button--unstyled padding-105 text-center"
|
||||
name="btn-cancel-click"
|
||||
data-close-modal
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</form>
|
||||
{% elif not is_domain_request_form or review_form_is_complete %}
|
||||
<button
|
||||
type="button"
|
||||
class="usa-button usa-button--unstyled padding-105 text-center"
|
||||
data-close-modal
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
{% endif %}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a
|
||||
href="#toggle-confirmation-modal"
|
||||
class="usa-button display-none show-confirmation-modal"
|
||||
aria-controls="toggle-confirmation-modal"
|
||||
data-open-modal
|
||||
>Open confirmation modal</a>
|
||||
<div
|
||||
class="usa-modal is-visible"
|
||||
id="toggle-confirmation-modal"
|
||||
aria-labelledby="Add contact information"
|
||||
aria-describedby="Add contact information"
|
||||
>
|
||||
<div class="usa-modal__content">
|
||||
<div class="usa-modal__main">
|
||||
<h2 class="usa-modal__heading" id="modal-1-heading">
|
||||
Add contact information
|
||||
</h2>
|
||||
<div class="usa-prose">
|
||||
<p id="modal-1-description">
|
||||
.Gov domain registrants must maintain accurate contact information in the .gov registrar.
|
||||
Before you can manage your domain, we need you to add your contact information.
|
||||
</p>
|
||||
</div>
|
||||
<div class="usa-modal__footer">
|
||||
<ul class="usa-button-group">
|
||||
<li class="usa-button-group__item">
|
||||
<button
|
||||
type="button"
|
||||
class="usa-button padding-105 text-center"
|
||||
data-close-modal
|
||||
>
|
||||
Add contact information
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
{% block content_bottom %}
|
||||
|
@ -105,3 +92,7 @@ Edit your User Profile |
|
|||
</div>
|
||||
</main>
|
||||
{% endblock content_bottom %}
|
||||
|
||||
{% block footer %}
|
||||
{% include "includes/footer.html" with show_manage_your_domains=user_finished_setup %}
|
||||
{% endblock footer %}
|
||||
|
|
|
@ -41,8 +41,8 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
form = self.form_class(instance=self.object)
|
||||
context = self.get_context_data(object=self.object, form=form)
|
||||
|
||||
if hasattr(self.object, "finished_setup") and not self.object.finished_setup:
|
||||
context["show_confirmation_modal"]
|
||||
if hasattr(self.user, "finished_setup") and not self.user.finished_setup:
|
||||
context["show_confirmation_modal"] = True
|
||||
|
||||
return_to_request = request.GET.get("return_to_request")
|
||||
if return_to_request:
|
||||
|
@ -70,10 +70,15 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
|
||||
# The text for the back button on this page
|
||||
context["profile_back_button_text"] = "Go to manage your domains"
|
||||
context["show_back_button"] = True
|
||||
context["show_back_button"] = False
|
||||
|
||||
if hasattr(self.user, "finished_setup") and self.user.finished_setup:
|
||||
context["user_finished_setup"] = True
|
||||
context["show_back_button"] = True
|
||||
|
||||
return context
|
||||
|
||||
|
||||
def get_success_url(self):
|
||||
"""Redirect to the user's profile page."""
|
||||
|
||||
|
@ -97,6 +102,12 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
else:
|
||||
return self.form_invalid(form)
|
||||
|
||||
def form_invalid(self, form):
|
||||
"""If the form is invalid, conditionally display an additional error."""
|
||||
if hasattr(self.user, "finished_setup") and not self.user.finished_setup:
|
||||
messages.error(self.request, "Before you can manage your domain, we need you to add contact information.")
|
||||
return super().form_invalid(form)
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Handle successful and valid form submissions."""
|
||||
form.save()
|
||||
|
@ -108,9 +119,9 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
|
||||
def get_object(self, queryset=None):
|
||||
"""Override get_object to return the logged-in user's contact"""
|
||||
user = self.request.user # get the logged in user
|
||||
if hasattr(user, "contact"): # Check if the user has a contact instance
|
||||
return user.contact
|
||||
self.user = self.request.user # get the logged in user
|
||||
if hasattr(self.user, "contact"): # Check if the user has a contact instance
|
||||
return self.user.contact
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue