2022-05-16 20:20:36 +00:00
|
|
|
# Functions not dependent on advlabdb.models
|
|
|
|
|
2022-05-29 17:03:54 +00:00
|
|
|
from random import choice
|
|
|
|
from string import ascii_letters, digits
|
|
|
|
|
2022-05-16 20:20:36 +00:00
|
|
|
from sqlalchemy import func, select
|
|
|
|
|
2022-05-29 17:03:54 +00:00
|
|
|
from . import app, db
|
|
|
|
|
|
|
|
|
|
|
|
def randomPassword():
|
|
|
|
password_length = app.config["SECURITY_PASSWORD_LENGTH_MIN"]
|
|
|
|
return "".join(choice(ascii_letters + digits) for i in range(password_length))
|
2022-05-16 20:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def reportBadAttempt(message):
|
|
|
|
print("BAD ATTEMPT:", message) # TODO: Log
|
|
|
|
|
|
|
|
|
|
|
|
def get_count(table):
|
|
|
|
return db.session.scalar(select(func.count()).select_from(table))
|
|
|
|
|
|
|
|
|
|
|
|
def get_first(table):
|
|
|
|
return db.session.execute(table.limit(1)).scalars().first()
|