diff options
| author | Bobby <[email protected]> | 2024-08-25 23:27:40 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-08-25 23:27:40 -0400 |
| commit | ced2c54b4e1d2aa1757c1a58a0b624a36bda5c21 (patch) | |
| tree | 2f1e5047c13cb15df6311e42d57c830d11d77364 /authentication/views.py | |
| parent | a99b3870b362bda483fc1009895447c58cabfff4 (diff) | |
| download | yugen-ced2c54b4e1d2aa1757c1a58a0b624a36bda5c21.tar.xz yugen-ced2c54b4e1d2aa1757c1a58a0b624a36bda5c21.zip | |
Ability to save preferences
Diffstat (limited to 'authentication/views.py')
| -rw-r--r-- | authentication/views.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/authentication/views.py b/authentication/views.py index a2b407b..781aa99 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -5,7 +5,9 @@ from django.shortcuts import redirect, render def callback(request): - # Coming from Discord OAuth2 + if request.user.is_authenticated: + return redirect("home:index") + code = request.GET.get("code") if not code: return render(request, "messages/unauthorized.html", {"error": "You can't access the site if you keep cancelling the login!", "redirect_uri": get_redirect_uri()}) @@ -18,7 +20,7 @@ def callback(request): user = authenticate_user(exchange_response=response) if not user: - return render(request, "messages/unauthorized.html", {"redirect_uri": get_redirect_uri()}) + return redirect("auth:unauthorized") next_url = request.session.pop("next", None) # login the user and redirect to the referrer @@ -28,3 +30,9 @@ def callback(request): def logout_user(request): logout(request) return HttpResponseRedirect(request.META.get("HTTP_REFERER")) + +def unauthorized(request): + if request.user.is_authenticated: + return redirect("home:index") + + return render(request, "messages/unauthorized.html", {"redirect_uri": get_redirect_uri(), "error": "You are not part of our elite cult!"}) |
