lenticular_cloud2/lenticular_cloud/auth_providers.py

56 lines
1.2 KiB
Python
Raw Normal View History

2020-05-09 18:00:07 +00:00
from flask import current_app
2022-06-18 17:35:05 +00:00
from flask_wtf import FlaskForm
2023-12-25 17:55:20 +00:00
from .form.auth import PasswordForm
2022-06-18 17:35:05 +00:00
from hmac import compare_digest as compare_hash
import crypt
from .model import User
import logging
logger = logging.getLogger(__name__)
2020-05-09 18:00:07 +00:00
class AuthProvider:
@classmethod
def get_name(csl):
return csl.__name__
@staticmethod
2022-06-18 17:35:05 +00:00
def get_form() -> FlaskForm:
2020-05-09 18:00:07 +00:00
return
@staticmethod
2022-06-18 17:35:05 +00:00
def check_auth(user: User, form) -> bool:
2020-05-09 18:00:07 +00:00
'''
checks the submited form is valid
return true if user is allowed to auth
'''
return False
2022-06-18 17:35:05 +00:00
class PasswordAuthProvider(AuthProvider):
2020-05-09 18:00:07 +00:00
@staticmethod
2022-06-18 17:35:05 +00:00
def get_form() -> FlaskForm:
2020-05-09 18:00:07 +00:00
return PasswordForm(prefix='password')
@staticmethod
2022-06-18 17:35:05 +00:00
def check_auth(user: User, form: FlaskForm) -> bool:
if isinstance(form.data['password'], str):
return PasswordAuthProvider.check_auth_internal(user, form.data['password'])
else:
2020-05-09 18:00:07 +00:00
return False
2022-06-18 17:35:05 +00:00
@staticmethod
def check_auth_internal(user: User, password: str) -> bool:
return compare_hash(crypt.crypt(password, user.password_hashed),user.password_hashed)
2020-05-09 18:00:07 +00:00
AUTH_PROVIDER_LIST = [
2023-12-25 18:44:38 +00:00
PasswordAuthProvider
2020-05-09 18:00:07 +00:00
]
2022-02-06 22:57:01 +00:00
#print(LdapAuthProvider.get_name())
2020-05-09 18:00:07 +00:00