Added flag handling to auth controller #440
This commit is contained in:
parent
4ccb57e6a3
commit
7c8c2bef70
@ -14,7 +14,10 @@ from bot_api.model.reset_password_dto import ResetPasswordDTO
|
||||
from bot_api.model.token_dto import TokenDTO
|
||||
from bot_api.model.update_auth_user_dto import UpdateAuthUserDTO
|
||||
from bot_api.route.route import Route
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_data.model.auth_role_enum import AuthRoleEnum
|
||||
from bot_data.model.technician_config import TechnicianConfig
|
||||
|
||||
|
||||
class AuthController:
|
||||
@ -30,6 +33,7 @@ class AuthController:
|
||||
mail_settings: EMailClientSettings,
|
||||
mailer: EMailClientABC,
|
||||
auth_service: AuthServiceABC,
|
||||
technician_config: TechnicianConfig,
|
||||
):
|
||||
self._config = config
|
||||
self._env = env
|
||||
@ -39,6 +43,7 @@ class AuthController:
|
||||
self._mail_settings = mail_settings
|
||||
self._mailer = mailer
|
||||
self._auth_service = auth_service
|
||||
self._technician_config = technician_config
|
||||
|
||||
@Route.get(f"{BasePath}/users")
|
||||
@Route.authorize(role=AuthRoleEnum.admin)
|
||||
@ -70,17 +75,32 @@ class AuthController:
|
||||
|
||||
@Route.post(f"{BasePath}/register")
|
||||
async def register(self):
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
self._technician_config.feature_flags, FeatureFlagsEnum.basic_registration
|
||||
):
|
||||
return
|
||||
|
||||
dto: AuthUserDTO = JSONProcessor.process(AuthUserDTO, request.get_json(force=True, silent=True))
|
||||
self._auth_service.add_auth_user(dto)
|
||||
return "", 200
|
||||
|
||||
@Route.post(f"{BasePath}/register-by-id/<id>")
|
||||
async def register_id(self, id: str):
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
self._technician_config.feature_flags, FeatureFlagsEnum.basic_registration
|
||||
):
|
||||
return
|
||||
|
||||
result = await self._auth_service.confirm_email_async(id)
|
||||
return jsonify(result)
|
||||
|
||||
@Route.post(f"{BasePath}/login")
|
||||
async def login(self) -> Response:
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
self._technician_config.feature_flags, FeatureFlagsEnum.basic_login
|
||||
):
|
||||
return jsonify({})
|
||||
|
||||
dto: AuthUserDTO = JSONProcessor.process(AuthUserDTO, request.get_json(force=True, silent=True))
|
||||
result = await self._auth_service.login_async(dto)
|
||||
return jsonify(result.to_dict())
|
||||
@ -100,6 +120,11 @@ class AuthController:
|
||||
|
||||
@Route.post(f"{BasePath}/forgot-password/<email>")
|
||||
async def forgot_password(self, email: str):
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
self._technician_config.feature_flags, FeatureFlagsEnum.basic_login
|
||||
):
|
||||
return "", 409
|
||||
|
||||
await self._auth_service.forgot_password_async(email)
|
||||
return "", 200
|
||||
|
||||
@ -110,6 +135,11 @@ class AuthController:
|
||||
|
||||
@Route.post(f"{BasePath}/reset-password")
|
||||
async def reset_password(self):
|
||||
if not FeatureFlagsSettings.get_flag_from_dict(
|
||||
self._technician_config.feature_flags, FeatureFlagsEnum.basic_login
|
||||
):
|
||||
return "", 409
|
||||
|
||||
dto: ResetPasswordDTO = JSONProcessor.process(ResetPasswordDTO, request.get_json(force=True, silent=True))
|
||||
await self._auth_service.reset_password_async(dto)
|
||||
return "", 200
|
||||
|
Loading…
Reference in New Issue
Block a user