mirror of
https://github.com/ReVanced/revanced-api.git
synced 2026-01-18 08:53:57 +00:00
feat: Add announcements endpoints (#91)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alexandre Teles (afterSt0rm) <alexandre.teles@ufba.br>
This commit is contained in:
40
auth.py
Normal file
40
auth.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
import secrets
|
||||
import string
|
||||
from data.database import Session
|
||||
|
||||
from sanic_beskar import Beskar
|
||||
|
||||
from data.models import UserDbModel
|
||||
|
||||
beskar = Beskar()
|
||||
|
||||
|
||||
def configure_auth(app):
|
||||
app.config.SECRET_KEY = os.environ.get("SECRET_KEY").join(
|
||||
secrets.choice(string.ascii_letters) for i in range(15)
|
||||
)
|
||||
app.config["TOKEN_ACCESS_LIFESPAN"] = {"hours": 24}
|
||||
app.config["TOKEN_REFRESH_LIFESPAN"] = {"days": 30}
|
||||
beskar.init_app(app, UserDbModel)
|
||||
|
||||
_init_default_user()
|
||||
|
||||
|
||||
def _init_default_user():
|
||||
username = os.environ.get("USERNAME")
|
||||
password = os.environ.get("PASSWORD")
|
||||
|
||||
if not username or not password:
|
||||
raise Exception("Missing USERNAME or PASSWORD environment variables")
|
||||
|
||||
session = Session()
|
||||
|
||||
existing_user = session.query(UserDbModel).filter_by(username=username).first()
|
||||
if not existing_user:
|
||||
session.add(
|
||||
UserDbModel(username=username, password=beskar.hash_password(password))
|
||||
)
|
||||
session.commit()
|
||||
|
||||
session.close()
|
||||
Reference in New Issue
Block a user