33
44import structlog
55from csh_ldap import CSHLDAP
6- from flask import Flask , redirect , render_template , g
6+ from flask import Flask , redirect , render_template , request , g
77from flask_migrate import Migrate
88from flask_gzip import Gzip
99from flask_pyoidc .flask_pyoidc import OIDCAuthentication
10+ from flask_pyoidc .provider_configuration import ProviderConfiguration , ClientMetadata
1011from flask_sqlalchemy import SQLAlchemy
1112
1213import sentry_sdk
3940 app .config ['LDAP_BIND_PW' ],
4041 ro = app .config ['LDAP_RO' ])
4142
42- auth = OIDCAuthentication (app , issuer = app .config ["OIDC_ISSUER" ],
43- client_registration_info = app .config ["OIDC_CLIENT_CONFIG" ])
43+ client_metadata = ClientMetadata (app .config ["OIDC_CLIENT_CONFIG" ])
44+ provider_config = ProviderConfiguration (issuer = app .config ["OIDC_ISSUER" ], client_registration_info = client_metadata )
45+
46+ auth = OIDCAuthentication ({'default' : provider_config }, app )
4447
4548app .secret_key = app .config ["SECRET_KEY" ]
4649
@@ -55,7 +58,6 @@ def start_of_year():
5558# pylint: disable=C0413
5659from .models .models import UserLog
5760
58-
5961# Configure Logging
6062def request_processor (logger , log_method , event_dict ): # pylint: disable=unused-argument, redefined-outer-name
6163 if 'request' in event_dict :
@@ -99,6 +101,7 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unuse
99101# pylint: disable=wrong-import-order
100102from conditional .util import context_processors
101103from conditional .util .auth import get_user
104+ from conditional .util .member import gatekeep_status
102105from .blueprints .dashboard import dashboard_bp # pylint: disable=ungrouped-imports
103106from .blueprints .attendance import attendance_bp
104107from .blueprints .major_project_submission import major_project_bp
@@ -137,7 +140,7 @@ def static_proxy(path):
137140
138141
139142@app .route ('/' )
140- @auth .oidc_auth
143+ @auth .oidc_auth ( "default" )
141144def default_route ():
142145 return redirect ('/dashboard' )
143146
@@ -156,12 +159,25 @@ def health():
156159 return {'status' : 'ok' }
157160
158161
162+ @app .route ("/gatekeep/<username>" )
163+ def gatekeep (username ):
164+ token = request .headers .get ("X-VOTE-TOKEN" , "" )
165+ if token != app .config ["VOTE_TOKEN" ]:
166+ return "Users cannot access this page" , 403
167+ try :
168+ gatekeep_data = gatekeep_status (username )
169+ except KeyError :
170+ return "" , 404
171+
172+ return gatekeep_data , 200
173+
174+
159175@app .errorhandler (404 )
160176@app .errorhandler (500 )
161- @auth .oidc_auth
177+ @auth .oidc_auth ( "default" )
162178@get_user
163179def route_errors (error , user_dict = None ):
164- data = dict ()
180+ data = {}
165181
166182 # Handle the case where the header isn't present
167183 if user_dict ['username' ] is not None :
0 commit comments