forked from Github-Mirrors/canaille
fix: SQL backend password scheme loading
Use Backend.instance instead of flask.current_app, so it allows the backend to be loaded independently from the Flask context.
This commit is contained in:
parent
c8f8e9fd06
commit
fdf8f1e550
1 changed files with 9 additions and 3 deletions
|
@ -20,6 +20,7 @@ from sqlalchemy_utils import force_auto_coercion
|
||||||
|
|
||||||
import canaille.core.models
|
import canaille.core.models
|
||||||
import canaille.oidc.models
|
import canaille.oidc.models
|
||||||
|
from canaille.backends import Backend
|
||||||
from canaille.backends.models import BackendModel
|
from canaille.backends.models import BackendModel
|
||||||
|
|
||||||
from .backend import Base
|
from .backend import Base
|
||||||
|
@ -63,6 +64,13 @@ membership_association_table = Table(
|
||||||
class User(canaille.core.models.User, Base, SqlAlchemyModel):
|
class User(canaille.core.models.User, Base, SqlAlchemyModel):
|
||||||
__tablename__ = "user"
|
__tablename__ = "user"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default_password_arguments(**kwargs):
|
||||||
|
return dict(
|
||||||
|
schemes=Backend.instance.config["CANAILLE_SQL"]["PASSWORD_SCHEMES"],
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
id: Mapped[str] = mapped_column(
|
id: Mapped[str] = mapped_column(
|
||||||
String, primary_key=True, default=lambda: str(uuid.uuid4())
|
String, primary_key=True, default=lambda: str(uuid.uuid4())
|
||||||
)
|
)
|
||||||
|
@ -75,9 +83,7 @@ class User(canaille.core.models.User, Base, SqlAlchemyModel):
|
||||||
user_name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
user_name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
|
||||||
password: Mapped[str] = mapped_column(
|
password: Mapped[str] = mapped_column(
|
||||||
PasswordType(
|
PasswordType(
|
||||||
onload=lambda **kwargs: dict(
|
onload=default_password_arguments,
|
||||||
schemes=current_app.config["CANAILLE_SQL"]["PASSWORD_SCHEMES"], **kwargs
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
nullable=True,
|
nullable=True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue