diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2022-01-10 18:40:12 +0100 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2022-01-10 18:40:22 +0100 |
commit | 0d3883fc76751d70871743e3eeb3d83cfe458e39 (patch) | |
tree | 21b2f9cffd3270615460cf4501da124a78537a72 /accounts/views.py | |
parent | get version, commit_id and branch only at startup (diff) | |
download | scout-subs-0d3883fc76751d70871743e3eeb3d83cfe458e39.tar.gz scout-subs-0d3883fc76751d70871743e3eeb3d83cfe458e39.zip |
add option to disable oauth
Diffstat (limited to '')
-rw-r--r-- | accounts/views.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/accounts/views.py b/accounts/views.py index 2455d73..cd17552 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -30,6 +30,7 @@ from pdf2image.exceptions import ( oauth = OAuth() hitobito = oauth.register(name="hitobito") api_url = settings.AUTHLIB_OAUTH_CLIENTS["hitobito"]["api_url"] +MIDATA_ENABLED = settings.OAUTH_ENABLED # override to remove help text class RegisterForm(UserCreationForm): @@ -96,9 +97,13 @@ def copy_from_midata(request, usercode): class CustomLoginView(LoginView): form_class = AuthForm + extra_context = {'midata_enabled': MIDATA_ENABLED} # send to hitobito request to get token def oauth_login(request): + if not MIDATA_ENABLED: + return None + redirect_uri = request.build_absolute_uri(reverse('auth')) # forward next page requested by user @@ -111,6 +116,9 @@ def oauth_login(request): # callback after acquiring token def auth(request): + if not MIDATA_ENABLED: + return None + token = hitobito.authorize_access_token(request) # request data from user account @@ -152,6 +160,9 @@ def auth(request): # send to hitobito request to get token @login_required def oauth_connect(request): + if not MIDATA_ENABLED: + return None + redirect_uri = request.build_absolute_uri(reverse('auth_connect')) return hitobito.authorize_redirect(request, redirect_uri) @@ -171,6 +182,9 @@ def oauth_disconnect(request): # callback after acquiring token @login_required def auth_connect(request): + if not MIDATA_ENABLED: + return None + token = hitobito.authorize_access_token(request) # request data from user account @@ -603,6 +617,7 @@ def personal_wrapper(request, errors): 'usable_password': usable_password, 'settings_active': settings_active, 'personal_active': personal_active, + 'midata_enabled': MIDATA_ENABLED, } return render(request, 'accounts/index.html', context) |