mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
implement CLI password recovery (hacky :omg:)
+ rewrite migrations logic + rename encode_password to hash_password + update image sizes (add medium size) + rename image endpoints
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
from app.models.user import User
|
||||
from app.utils.auth import encode_password
|
||||
from app.utils.auth import hash_password
|
||||
from app.db.sqlite.utils import SQLiteManager
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class SQLiteAuthMethods:
|
||||
"""
|
||||
user = {
|
||||
"username": "admin",
|
||||
"password": encode_password("admin"),
|
||||
"password": hash_password("admin"),
|
||||
"roles": json.dumps(["admin"]),
|
||||
}
|
||||
return SQLiteAuthMethods.insert_user(user)
|
||||
@@ -56,7 +56,7 @@ class SQLiteAuthMethods:
|
||||
"""
|
||||
user = {
|
||||
"username": "guest",
|
||||
"password": encode_password("guest"),
|
||||
"password": hash_password("guest"),
|
||||
"roles": json.dumps(["guest"]),
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class SQLiteAuthMethods:
|
||||
"""
|
||||
Update a user in the database.
|
||||
|
||||
:param user: A dict with the username, password and roles.
|
||||
:param user: A dict with the user id and the fields to update. Ommited fields will not be updated.
|
||||
"""
|
||||
# get all user dict keys
|
||||
keys = list(user.keys())
|
||||
@@ -75,6 +75,7 @@ class SQLiteAuthMethods:
|
||||
{', '.join([f"{key} = :{key}" for key in keys if key != 'id'])}
|
||||
WHERE id = :id
|
||||
"""
|
||||
print(sql, user)
|
||||
|
||||
with SQLiteManager(userdata_db=True) as cur:
|
||||
cur.execute(sql, user)
|
||||
|
||||
@@ -7,9 +7,9 @@ from app.db.sqlite.utils import SQLiteManager
|
||||
|
||||
class MigrationManager:
|
||||
@staticmethod
|
||||
def get_version() -> int:
|
||||
def get_index() -> int:
|
||||
"""
|
||||
Returns the latest userdata database version.
|
||||
Returns the latest databases migrations index.
|
||||
"""
|
||||
sql = "SELECT * FROM dbmigrations"
|
||||
with SQLiteManager() as cur:
|
||||
@@ -21,9 +21,9 @@ class MigrationManager:
|
||||
|
||||
# 👇 Setters 👇
|
||||
@staticmethod
|
||||
def set_version(version: int):
|
||||
def set_index(version: int):
|
||||
"""
|
||||
Sets the userdata pre-init database version.
|
||||
Updates the databases migrations index.
|
||||
"""
|
||||
sql = "UPDATE dbmigrations SET version = ? WHERE id = 1"
|
||||
with SQLiteManager() as cur:
|
||||
|
||||
Reference in New Issue
Block a user