diff --git a/eac/__init__.py b/eac/__init__.py index dd22928..97ba7a4 100644 --- a/eac/__init__.py +++ b/eac/__init__.py @@ -9,7 +9,7 @@ import hmac from hashlib import sha1 import base64 -from typing import Any +from typing import Any, Union import jwt from requests.models import HTTPError @@ -108,6 +108,12 @@ def _index() -> str: services=services) +@APP.route('/status') +@_AUTH.oidc_auth('default') +def _status() -> tuple[str, int]: + return render_template('callback.html'), 200 + + @APP.route('/slack', methods=['GET']) @_AUTH.oidc_auth('default') def _auth_slack() -> werkzeug.Response: @@ -159,7 +165,7 @@ def _auth_github() -> werkzeug.Response: @APP.route('/github/return', methods=['GET']) @_AUTH.oidc_auth('default') -def _github_landing() -> tuple[str, int]: +def _github_landing() -> Union[werkzeug.Response, tuple[str, int]]: # Determine if we have a valid reason to do things state = request.args.get('state') if state != APP.config['STATE']: @@ -209,7 +215,13 @@ def _github_landing() -> tuple[str, int]: member = _LDAP.get_member(uid, uid=True) _link_github(github_username, github_id, member, user_token) - return render_template('callback.html'), 200 + status_title = 'Linked Github!' + status = f'Added {github_username} to CSH Github org, you do not have to accept the email invite' + + status_title_encoded = urllib.parse.quote(status_title, safe='') + status_encoded = urllib.parse.quote(status, safe='') + return redirect( + f'/status?status-title={status_title_encoded}&status={status_encoded}') def _get_github_jwt() -> str: diff --git a/eac/static/actions.js b/eac/static/actions.js index c278f1c..58222ce 100644 --- a/eac/static/actions.js +++ b/eac/static/actions.js @@ -1,10 +1,32 @@ -(function () { - const reload = () => window.location.reload(); +function showModal(statusTitle, status) { + const modalEl = document.querySelector('#statusModal') + const modal = new bootstrap.Modal(modalEl) + + const modalCloseBtn = modalEl.querySelector('#statusCloseButton') + modalCloseBtn.addEventListener('click', () => modal.hide()) + + const modalTitle = modalEl.querySelector('.modal-title') + modalTitle.append(statusTitle) + + const modalBody = modalEl.querySelector('.modal-body') + modalBody.append(status) + + $("#statusModal").on("hidden.bs.modal", () => { + window.location.reload() + }) + + modal.show() + + return modal; +} + +window.addEventListener('load', () => { const controls = document.querySelectorAll("button[data-service]"); + const reload = () => window.location.reload(); for (const control of controls) { const serviceName = control.dataset.service; - const endpoint = window.location + serviceName; + const endpoint = serviceName; const unlink = control.dataset.action === "unlink"; control.addEventListener('click', () => { @@ -24,10 +46,26 @@ const timer = setInterval(() => { if (popup.closed) { clearInterval(timer); + reload(); } + try { + if (popup.location.pathname == '/status') { + clearInterval(timer); + + const query = new URLSearchParams(popup.location.search); + popup.close(); + + const statusTitle = query.get('status-title'); + const status = query.get('status'); + + showModal(statusTitle, status); + } + } catch { + // do this because every time you try and access the location of a window with a different origin it errors + } }, 500); } }); } -}()); +}); diff --git a/eac/templates/callback.html b/eac/templates/callback.html index 80cfc54..d22b3db 100644 --- a/eac/templates/callback.html +++ b/eac/templates/callback.html @@ -2,9 +2,6 @@