mirror of
https://git.wownero.com/wownero/YellWOWPages.git
synced 2024-08-15 01:03:25 +00:00
27 lines
No EOL
789 B
Python
27 lines
No EOL
789 B
Python
import re
|
|
|
|
import peewee
|
|
from quart import session, redirect, url_for
|
|
from quart_keycloak import Keycloak, KeycloakAuthToken, KeycloakLogoutRequest
|
|
from yellow.factory import keycloak
|
|
from yellow.models import User
|
|
|
|
|
|
@keycloak.after_login()
|
|
async def handle_user_login(auth_token: KeycloakAuthToken):
|
|
username = auth_token.username
|
|
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 = None
|
|
|
|
if not user:
|
|
# create new user if it does not exist yet
|
|
user = User.create(id=uid, username=username)
|
|
|
|
# user is now logged in
|
|
session['user'] = user.to_json()
|
|
return redirect(url_for('bp_routes.dashboard')) |