add failed page

This commit is contained in:
Francis 2020-07-22 21:34:19 +02:00
parent 1644e61d98
commit 6de3f2ab40
No known key found for this signature in database
GPG key ID: 071BEA4C2B10077C
2 changed files with 17 additions and 6 deletions

View file

@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block title %}Login Failed{% endblock %}
{% block content %}
<h2>Login Failed</h2>
{% if error %}
<h3>{{ error }}</h3>
{% endif %}
{% endblock %}

View file

@ -4,7 +4,7 @@ import requests
from django.conf import settings from django.conf import settings
from django.contrib.auth import login from django.contrib.auth import login
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.shortcuts import redirect from django.shortcuts import redirect, render
import users import users
from users.models import CustomUser from users.models import CustomUser
@ -26,7 +26,8 @@ def register(_):
def register_callback(req: HttpRequest): def register_callback(req: HttpRequest):
if 'code' not in req.GET or 'error' in req.GET: if 'code' not in req.GET or 'error' in req.GET:
return login_fail('') error = req.GET['error'] if 'error' in req.GET else None
return login_fail(req, error)
try: try:
access_token = get_access_token(req.GET['code']) access_token = get_access_token(req.GET['code'])
@ -39,12 +40,11 @@ def register_callback(req: HttpRequest):
return redirect('/') return redirect('/')
except OAuthException as e: except OAuthException as e:
logger.error(e) logger.error(e)
return login_fail(str(e)) return login_fail(req, str(e))
def login_fail(error: str): def login_fail(request, error: str = None):
# TODO: create login failed page return render(request, "oauth/failed.html", {'error': error})
return redirect('/')
def validate_user(zeus_id, username) -> CustomUser: def validate_user(zeus_id, username) -> CustomUser: