mirror of
https://git.wownero.com/wownero/YellWOWPages.git
synced 2024-08-15 01:03:25 +00:00
Fix for new keycloak version
This commit is contained in:
parent
8960768a52
commit
b870c61084
2 changed files with 12 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
|
||||
import peewee
|
||||
from quart import session, redirect, url_for
|
||||
from quart import session, redirect, url_for, current_app
|
||||
from quart_keycloak import Keycloak, KeycloakAuthToken, KeycloakLogoutRequest
|
||||
from yellow.factory import keycloak
|
||||
from yellow.models import User
|
||||
|
@ -10,18 +10,25 @@ from yellow.models import User
|
|||
@keycloak.after_login()
|
||||
async def handle_user_login(auth_token: KeycloakAuthToken):
|
||||
username = auth_token.username
|
||||
uid = auth_token.sub
|
||||
|
||||
if not re.match(r"^[a-zA-Z0-9_\.-]+$", username):
|
||||
raise Exception("bad username")
|
||||
|
||||
try:
|
||||
user = User.select().where(User.id == uid).get()
|
||||
except peewee.DoesNotExist:
|
||||
user = User.select().where(User.username == username).get()
|
||||
except Exception as ex:
|
||||
user = None
|
||||
|
||||
if not user:
|
||||
# create new user if it does not exist yet
|
||||
user = User.create(id=uid, username=username)
|
||||
current_app.logger.info(f'User {username} not found, creating')
|
||||
try:
|
||||
user = User.create(id=uid, username=username)
|
||||
except Exception as ex:
|
||||
current_app.logger.debug(f'User {username}, creation error')
|
||||
raise
|
||||
|
||||
# user is now logged in
|
||||
session['user'] = user.to_json()
|
||||
return redirect(url_for('bp_routes.dashboard'))
|
||||
return redirect(url_for('bp_routes.dashboard'))
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="refresh" content="3; URL={{url}}">
|
||||
<title>Such {{code}} error :(</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
|
||||
<link rel="stylesheet" href="../../static/colors.css">
|
||||
|
|
Loading…
Reference in a new issue