add failed page
This commit is contained in:
parent
1644e61d98
commit
6de3f2ab40
2 changed files with 17 additions and 6 deletions
11
oauth/templates/oauth/failed.html
Normal file
11
oauth/templates/oauth/failed.html
Normal 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 %}
|
|
@ -4,7 +4,7 @@ import requests
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import login
|
||||
from django.http.request import HttpRequest
|
||||
from django.shortcuts import redirect
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
import users
|
||||
from users.models import CustomUser
|
||||
|
@ -26,7 +26,8 @@ def register(_):
|
|||
|
||||
def register_callback(req: HttpRequest):
|
||||
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:
|
||||
access_token = get_access_token(req.GET['code'])
|
||||
|
@ -39,12 +40,11 @@ def register_callback(req: HttpRequest):
|
|||
return redirect('/')
|
||||
except OAuthException as e:
|
||||
logger.error(e)
|
||||
return login_fail(str(e))
|
||||
return login_fail(req, str(e))
|
||||
|
||||
|
||||
def login_fail(error: str):
|
||||
# TODO: create login failed page
|
||||
return redirect('/')
|
||||
def login_fail(request, error: str = None):
|
||||
return render(request, "oauth/failed.html", {'error': error})
|
||||
|
||||
|
||||
def validate_user(zeus_id, username) -> CustomUser:
|
||||
|
|
Loading…
Reference in a new issue