Skip to content

Commit 2bf681f

Browse files
authored
Changes to shore up a few minor issues around login (#2673)
1 parent 262db6e commit 2bf681f

File tree

5 files changed

+42
-38
lines changed

5 files changed

+42
-38
lines changed

frontend/public/src/containers/App.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Header from "../components/Header"
1919
import PrivateRoute from "../components/PrivateRoute"
2020

2121
import LoginPages from "./pages/login/LoginPages"
22+
import LoginSso from "./pages/login/LoginSso"
2223
import RegisterPages from "./pages/register/RegisterPages"
2324
import EditProfilePage from "./pages/profile/EditProfilePage"
2425
import AccountSettingsPage from "./pages/settings/AccountSettingsPage"
@@ -85,6 +86,10 @@ export class App extends React.Component<Props, void> {
8586
path={urljoin(match.url, String(routes.login))}
8687
component={LoginPages}
8788
/>
89+
<Route
90+
path={urljoin(match.url, String(routes.apiGatewayLogin))}
91+
component={LoginSso}
92+
/>
8893
<Route
8994
path={urljoin(match.url, String(routes.register))}
9095
component={RegisterPages}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @flow
2+
import React from "react"
3+
import { Redirect } from "react-router-dom"
4+
5+
const LoginSso = () => {
6+
return <Redirect to="/login" />
7+
}
8+
9+
export default LoginSso

main/settings.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@
115115
description="Allow cookies to be sent in cross-site HTTP requests",
116116
)
117117

118+
SESSION_COOKIE_DOMAIN = get_string(
119+
name="SESSION_COOKIE_DOMAIN",
120+
default=None,
121+
description="Domain to set the session cookie to.",
122+
)
123+
SESSION_COOKIE_NAME = get_string(
124+
name="SESSION_COOKIE_NAME",
125+
default="mitxonline_sessionid",
126+
description="Name of the session cookie.",
127+
)
128+
118129
SECURE_SSL_REDIRECT = get_bool(
119130
name="MITX_ONLINE_SECURE_SSL_REDIRECT",
120131
default=True,

main/settings_test.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,6 @@
1111
from django.core.exceptions import ImproperlyConfigured
1212
from mitol.common import envs
1313

14-
# this is a test, but pylint thinks it ends up being unused
15-
# hence we import the entire module and assign it here
16-
# test_app_json_modified = pytest_utils.test_app_json_modified # noqa: ERA001
17-
18-
19-
# NOTE: this is temporarily inlined here until I can stabilize the test upstream in the library
20-
def test_app_json_modified():
21-
"""
22-
Pytest test that verifies app.json is up-to-date
23-
24-
To use this, you should import this into a test file somewhere in your project:
25-
26-
from mitol.common.pytest_utils import test_app_json_modified
27-
"""
28-
import json
29-
import logging
30-
31-
from mitol.common import envs
32-
33-
# this line was causing errors due to a loading error bug
34-
# envs.reload() # noqa: ERA001
35-
36-
with open("app.json") as app_json_file: # noqa: PTH123
37-
app_json = json.load(app_json_file)
38-
39-
generated_app_json = envs.generate_app_json()
40-
41-
if app_json != generated_app_json:
42-
logging.error(
43-
"Generated app.json does not match the app.json file. To fix this, run `./manage.py generate_app_json`"
44-
)
45-
46-
# pytest will print the difference
47-
assert json.dumps(app_json, sort_keys=True, indent=2) == json.dumps(
48-
generated_app_json, sort_keys=True, indent=2
49-
)
50-
5114

5215
@pytest.fixture(autouse=True)
5316
def settings_sandbox(monkeypatch):

main/views.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
mitx_online views
33
"""
44

5+
from urllib.parse import urljoin
6+
57
from django.conf import settings
68
from django.contrib.auth.views import redirect_to_login
7-
from django.http import HttpResponseNotFound, HttpResponseServerError
9+
from django.http import (
10+
HttpResponseNotFound,
11+
HttpResponseRedirect,
12+
HttpResponseServerError,
13+
)
814
from django.shortcuts import render
915
from django.template.loader import render_to_string
1016
from django.urls import reverse
@@ -31,6 +37,16 @@ def index(request, **kwargs): # noqa: ARG001
3137
"""
3238
The index view. Display available programs
3339
"""
40+
41+
# If we're getting sent here, and the APISIX middleware is enabled, we should
42+
# punt them to its login page instead.
43+
44+
if (
45+
request.path.startswith("/signin")
46+
and not settings.MITOL_APIGATEWAY_DISABLE_MIDDLEWARE
47+
):
48+
return HttpResponseRedirect(urljoin(settings.SITE_BASE_URL, "/login"))
49+
3450
context = get_base_context(request)
3551
return render(request, "index.html", context=context)
3652

0 commit comments

Comments
 (0)