Skip to content

Commit

Permalink
Merge pull request #861 from ministryofjustice/handle-login-fail
Browse files Browse the repository at this point in the history
Add login-fail page and recovery link to control panel.
  • Loading branch information
Nicholas Tollervey authored Dec 9, 2020
2 parents 8d0fc1e + 42ad280 commit 5d082bb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
8 changes: 5 additions & 3 deletions controlpanel/frontend/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ async def disconnect(self):
"""
self.streaming = False

# leave the group
group = sanitize_dns_label(self.scope.get("user").auth0_id)
await self.channel_layer.group_discard(group, self.channel_name)
# leave the group if user is logged in.
user = self.scope.get("user")
if user.is_authenticated:
group = sanitize_dns_label(user.auth0_id)
await self.channel_layer.group_discard(group, self.channel_name)


class BackgroundTaskConsumer(SyncConsumer):
Expand Down
19 changes: 19 additions & 0 deletions controlpanel/frontend/jinja2/login-fail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "base.html" %}

{% set page_title = "Login Failure" %}

{% block content %}
<div class="govuk-grid-row" id="reset-container">
<div class="govuk-grid-column-two-thirds">


<h2 class="govuk-heading-l">Login Failure</h2>

<p>Something went wrong when you tried to authenticate.</p>

<p>Please
<a href="https://{{ environment }}-analytics-moj.eu.auth0.com/v2/logout?returnTo=https%3A%2F%2Fcontrolpanel.services.{{ environment }}.mojanalytics.xyz%2Foidc%2Flogout%2F">reset your session</a>,
and try again.</p>
</div>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions controlpanel/frontend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
path("webapp-datasource-access/<int:pk>/delete/", views.RevokeAppAccess.as_view(), name="revoke-app-access"),
path("reset-user-home/", views.ResetHome.as_view(), name="home-reset"),
path("whats-new/", views.WhatsNew.as_view(), name="whats-new"),
path("login-fail/", views.LoginFail.as_view(), name="login-fail"),
path("releases/", views.ReleaseList.as_view(), name="list-tool-releases"),
path("release/new/", views.ReleaseCreate.as_view(), name="create-tool-release"),
path("release/<int:pk>/", views.ReleaseDetail.as_view(), name="manage-tool-release"),
Expand Down
1 change: 1 addition & 0 deletions controlpanel/frontend/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from controlpanel.frontend.views.reset import ResetHome
from controlpanel.frontend.views.whats_new import WhatsNew
from controlpanel.frontend.views.accessibility import Accessibility
from controlpanel.frontend.views.login_fail import LoginFail


class IndexView(LoginRequiredMixin, TemplateView):
Expand Down
13 changes: 13 additions & 0 deletions controlpanel/frontend/views/login_fail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic.base import TemplateView
import requests


class LoginFail(TemplateView):
template_name = "login-fail.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["environment"] = settings.ENV
return context
2 changes: 1 addition & 1 deletion controlpanel/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
LOGOUT_REDIRECT_URL = "/"

# URL where requests are redirected after a failed login
LOGIN_REDIRECT_URL_FAILURE = "/"
LOGIN_REDIRECT_URL_FAILURE = "/login-fail/"

# Length of time it takes for an OIDC ID token to expire (default 15m)
OIDC_RENEW_ID_TOKEN_EXPIRY_SECONDS = 15 * 60
Expand Down

0 comments on commit 5d082bb

Please sign in to comment.