2022-06-12 21:03:51 +01:00
|
|
|
from .data import load
|
|
|
|
from ..models import User
|
2022-08-20 10:56:43 +01:00
|
|
|
from ..tools.logs import write
|
2022-06-12 21:03:51 +01:00
|
|
|
|
2022-08-20 10:56:43 +01:00
|
|
|
from flask.helpers import abort, flash, redirect, url_for
|
2022-06-12 21:03:51 +01:00
|
|
|
from flask_login import current_user
|
2022-08-20 10:56:43 +01:00
|
|
|
from sqlalchemy.exc import SQLAlchemyError
|
2022-06-12 21:03:51 +01:00
|
|
|
|
|
|
|
from functools import wraps
|
|
|
|
|
|
|
|
def require_account_creation(function):
|
|
|
|
@wraps(function)
|
|
|
|
def wrapper(*args, **kwargs):
|
2022-08-20 10:56:43 +01:00
|
|
|
try:
|
|
|
|
if User.query.count() == 0:
|
|
|
|
flash('Please register a user account.', 'alert')
|
|
|
|
return redirect(url_for('admin._register'))
|
|
|
|
except SQLAlchemyError as exception:
|
|
|
|
write('system.log', f'Database error when checking for existing accounts: {exception}')
|
|
|
|
return abort(500)
|
2022-06-12 21:03:51 +01:00
|
|
|
return function(*args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
def disable_if_logged_in(function):
|
|
|
|
@wraps(function)
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
if current_user.is_authenticated: return abort(404)
|
|
|
|
return function(*args, **kwargs)
|
|
|
|
return wrapper
|