mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Removed fn, reduced queries in login flow
This commit is contained in:
parent
d78d51d091
commit
119c34535c
@ -10,7 +10,7 @@ Users = Users
|
||||
|
||||
try:
|
||||
# pylint: disable=unused-import
|
||||
from peewee import SqliteDatabase, fn
|
||||
from peewee import SqliteDatabase
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
|
||||
except ModuleNotFoundError as err:
|
||||
@ -20,11 +20,8 @@ logger = logging.getLogger(__name__)
|
||||
peewee_logger = logging.getLogger("peewee")
|
||||
peewee_logger.setLevel(logging.INFO)
|
||||
database = SqliteDatabase(
|
||||
helper.db_path
|
||||
# This is commented out after presenting issues when
|
||||
# moving from SQLiteDatabase to SqliteQueueDatabase
|
||||
# //TODO Enable tuning
|
||||
# pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
||||
helper.db_path,
|
||||
pragmas={"journal_mode": "wal", "cache_size": -1024 * 10}
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
import logging
|
||||
|
||||
from app.classes.models.users import Users
|
||||
from app.classes.models.users import helper_users
|
||||
from app.classes.shared.authentication import authentication
|
||||
from app.classes.shared.helpers import helper
|
||||
from app.classes.shared.main_models import fn
|
||||
from app.classes.web.base_handler import BaseHandler
|
||||
|
||||
try:
|
||||
@ -107,9 +106,8 @@ class PublicHandler(BaseHandler):
|
||||
entered_password = bleach.clean(self.get_argument("password"))
|
||||
|
||||
# pylint: disable=no-member
|
||||
user_data = Users.get_or_none(
|
||||
fn.Lower(Users.username) == entered_username.lower()
|
||||
)
|
||||
user_id = helper_users.get_user_id_by_name(entered_username.lower())
|
||||
user_data = helper_users.get_user_model(user_id)
|
||||
|
||||
# if we don't have a user
|
||||
if not user_data:
|
||||
@ -152,14 +150,9 @@ class PublicHandler(BaseHandler):
|
||||
)
|
||||
|
||||
# record this login
|
||||
q = (
|
||||
Users.select()
|
||||
.where(Users.username == entered_username.lower())
|
||||
.get()
|
||||
)
|
||||
q.last_ip = self.get_remote_ip()
|
||||
q.last_login = helper.get_time_as_string()
|
||||
q.save()
|
||||
user_data.last_ip = self.get_remote_ip()
|
||||
user_data.last_login = helper.get_time_as_string()
|
||||
user_data.save()
|
||||
|
||||
# log this login
|
||||
self.controller.management.add_to_audit_log(
|
||||
|
Loading…
Reference in New Issue
Block a user