Skip to content

Commit d9d9e45

Browse files
authored
Merge pull request #9 from devinmatte/master
Setting up multiple realms for freshmen login
2 parents ebc548d + 0c10c8f commit d9d9e45

File tree

9 files changed

+113
-79
lines changed

9 files changed

+113
-79
lines changed

config.env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
PORT = environ.get("PACKET_PORT", "8000")
77
SERVER_NAME = environ.get("PACKET_SERVER_NAME", IP + ":" + PORT)
88
SECRET_KEY = environ.get("PACKET_SECRET_KEY", "PLEASE_REPLACE_ME")
9+
REALM = environ.get("PACKET_REALM", "intro")
910

1011
# OpenID Connect SSO config
1112
OIDC_ISSUER = environ.get("PACKET_OIDC_ISSUER", "https://sso.csh.rit.edu/auth/realms/csh")

packet/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
flask_saml.FlaskSAML(app)
3636

3737
# pylint: disable=wrong-import-position
38-
from . import routes
38+
if app.config["REALM"] == "csh":
39+
from .routes import upperclassmen
40+
else:
41+
from .routes import freshmen
3942
from . import commands
4043
from . import models

packet/routes.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

packet/routes/freshmen.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from flask import render_template, redirect
2+
3+
from packet import auth, app
4+
from packet.ldap import ldap_get_live_onfloor, ldap_get_eboard
5+
from packet.utils import before_request
6+
7+
8+
@app.route("/")
9+
@before_request
10+
def index(info=None):
11+
return redirect("/packet/" + info['uid'], 302)
12+
13+
14+
@app.route("/packet/<uid>")
15+
@auth.oidc_auth
16+
@before_request
17+
def freshman_packet(uid, info=None):
18+
onfloor = ldap_get_live_onfloor()
19+
eboard = ldap_get_eboard()
20+
return render_template("packet.html", info=info, eboard=eboard, onfloor=onfloor, uid=uid)
21+
22+
23+
@app.route("/packets")
24+
@auth.oidc_auth
25+
@before_request
26+
def packets(info=None):
27+
freshmen = [
28+
{
29+
"name": "Testiboi",
30+
"signatures": 12,
31+
"uid": 111
32+
},
33+
{
34+
"name": "Ram Zallllllan",
35+
"signatures": 69,
36+
"uid": 420
37+
}
38+
]
39+
return render_template("active_packets.html", info=info, freshmen=freshmen)

packet/routes/upperclassmen.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from flask import render_template, redirect
2+
3+
from packet import auth, app
4+
from packet.ldap import ldap_get_live_onfloor, ldap_get_eboard
5+
from packet.utils import before_request
6+
7+
8+
@app.route("/")
9+
def index():
10+
return redirect("/packets", 302)
11+
12+
13+
@app.route("/packet/<uid>")
14+
@auth.oidc_auth
15+
@before_request
16+
def freshman_packet(uid, info=None):
17+
onfloor = ldap_get_live_onfloor()
18+
eboard = ldap_get_eboard()
19+
return render_template("packet.html", info=info, eboard=eboard, onfloor=onfloor, uid=uid)
20+
21+
22+
@app.route("/packets")
23+
@auth.oidc_auth
24+
@before_request
25+
def packets(info=None):
26+
freshmen = [
27+
{
28+
"name": "Testiboi",
29+
"signatures": 12,
30+
"uid": 111
31+
},
32+
{
33+
"name": "Ram Zallllllan",
34+
"signatures": 69,
35+
"uid": 420
36+
}
37+
]
38+
return render_template("active_packets.html", info=info, freshmen=freshmen)

packet/templates/include/nav.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ul class="navbar-nav mr-auto">
1212

1313
<li class="nav-item">
14-
<a class="nav-link" href="/">Active Packets</a>
14+
<a class="nav-link" href="/packets">Active Packets</a>
1515
</li>
1616

1717
</ul>
@@ -25,9 +25,11 @@
2525
</a>
2626

2727
<div class="dropdown-menu" aria-labelledby="user01">
28-
<a class="dropdown-item" href="/">Profile</a>
29-
<a class="dropdown-item" href="https://themeswitcher.csh.rit.edu/">Theme</a>
30-
<div class="dropdown-divider"></div>
28+
{% if info.realm == "csh" %}
29+
<a class="dropdown-item" href="/">Profile</a>
30+
<a class="dropdown-item" href="https://themeswitcher.csh.rit.edu/">Theme</a>
31+
<div class="dropdown-divider"></div>
32+
{% endif %}
3133
<a class="dropdown-item" href="/logout">Logout</a>
3234
</div>
3335

packet/templates/include/scripts.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
1111

12-
<script src="/static/js/adaptive-background.js"></script>
13-
1412
<script type="text/javascript">
1513
$(document).ready(function(){
1614
$('[data-toggle="tooltip"]').tooltip()

packet/utils.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,33 @@
1313
ldap_get_roomnumber,
1414
ldap_get_groups)
1515

16+
INTRO_REALM = "https://sso.csh.rit.edu/auth/realms/intro"
17+
1618

1719
def before_request(func):
1820
@wraps(func)
1921
def wrapped_function(*args, **kwargs):
20-
uuid = str(session["userinfo"].get("sub", ""))
2122
uid = str(session["userinfo"].get("preferred_username", ""))
22-
user_obj = _ldap.get_member(uid, uid=True)
23-
info = {
24-
"uuid": uuid,
25-
"uid": uid,
26-
"user_obj": user_obj,
27-
"member_info": get_member_info(uid),
28-
"color": requests.get('https://themeswitcher.csh.rit.edu/api/colour').content,
29-
"current_year": parse_account_year(str(datetime.datetime.now().strftime("%Y%m")))
30-
}
23+
24+
if session["id_token"]["iss"] == INTRO_REALM:
25+
info = {
26+
"realm": "intro",
27+
"uid": uid,
28+
"current_year": parse_account_year(str(datetime.datetime.now().strftime("%Y%m")))
29+
}
30+
else:
31+
uuid = str(session["userinfo"].get("sub", ""))
32+
user_obj = _ldap.get_member(uid, uid=True)
33+
info = {
34+
"realm": "csh",
35+
"uuid": uuid,
36+
"uid": uid,
37+
"user_obj": user_obj,
38+
"member_info": get_member_info(uid),
39+
"color": requests.get('https://themeswitcher.csh.rit.edu/api/colour').content,
40+
"current_year": parse_account_year(str(datetime.datetime.now().strftime("%Y%m")))
41+
}
42+
3143
kwargs["info"] = info
3244
return func(*args, **kwargs)
3345

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Flask==1.0.2
2-
Flask-pyoidc==1.3.0
2+
Flask-pyoidc>=1.3.0
33
flask_sqlalchemy==2.3.2
44
psycopg2==2.7.5
55
Flask-Migrate==2.2.1
6-
pylint==2.0.1
6+
pylint==2.1.1
77
flask_saml==0.4.3
88
gunicorn==19.7.1
9-
csh_ldap
9+
csh_ldap>=2.1.0

0 commit comments

Comments
 (0)