from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_bcrypt import Bcrypt

db = SQLAlchemy()
bcrypt = Bcrypt()

login_manager = LoginManager()

#Protection for user-sessions
login_manager.session_protection = "strong"

#Route users sends to if they are not logged in
login_manager.login_view = "auth.login_form"

#Flash messages incase of unauthrized access
login_manager.login_message = "Login to continue"
login_manager.login_message_category = "error"

@login_manager.user_loader
def load_user(user_id: str):
    from models import User
    return db.session.get(User, int(user_id))