auth password forgot and change tested
This commit is contained in:
parent
288a393719
commit
a4fd52c28a
|
|
@ -26,9 +26,10 @@ class Config:
|
|||
"/authentication/refresh",
|
||||
"/authentication/disconnect",
|
||||
"/authentication/create_password",
|
||||
"/authentication/change_password",
|
||||
"/authentication/reset_password",
|
||||
"/authentication/forgot",
|
||||
"/authentication/avatar",
|
||||
"/authentication/valid",
|
||||
"/api/Contact/Us/current_date",
|
||||
]
|
||||
|
||||
|
|
@ -40,7 +41,7 @@ class Config:
|
|||
|
||||
class ApiStatic:
|
||||
PLACEHOLDER = "https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg"
|
||||
FORGOT_LINK = "https://www.evyos.com.tr/auth/create-password/"
|
||||
FORGOT_LINK = "https://www.evyos.com.tr/password/create?tokenUrl="
|
||||
BLACKLIST_LINK = "https://www.evyos.com.tr/support/unknown-login-notice/"
|
||||
APP_DIR = "/home/berkay/git-evyos/api-managment-backend/"
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from api_events.events.authentication import (
|
|||
AuthenticationRefreshEventMethod,
|
||||
AuthenticationChangePasswordEventMethod,
|
||||
AuthenticationCreatePasswordEventMethod,
|
||||
AuthenticationResetPasswordEventMethod,
|
||||
AuthenticationDisconnectUserEventMethod,
|
||||
AuthenticationLogoutEventMethod,
|
||||
AuthenticationRefreshTokenEventMethod,
|
||||
|
|
@ -183,6 +184,7 @@ __all__ = [
|
|||
"AuthenticationRefreshEventMethod",
|
||||
"AuthenticationChangePasswordEventMethod",
|
||||
"AuthenticationCreatePasswordEventMethod",
|
||||
"AuthenticationResetPasswordEventMethod",
|
||||
"AuthenticationDisconnectUserEventMethod",
|
||||
"AuthenticationLogoutEventMethod",
|
||||
"AuthenticationRefreshTokenEventMethod",
|
||||
|
|
|
|||
|
|
@ -46,6 +46,12 @@ class AccountRecordsListEventMethods(MethodToEvent):
|
|||
completed=True, message="Update Build record", result=records
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def account_records_list_flt_res_or_ten(cls):
|
||||
"""
|
||||
FLT-RES | FLT-TEN | FLT-OWN aidatları görür
|
||||
"""
|
||||
return
|
||||
|
||||
class AccountRecordsCreateEventMethods(MethodToEvent):
|
||||
|
||||
|
|
|
|||
|
|
@ -433,8 +433,7 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
|||
status_code=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
if already_tokens := get_object_via_user_uu_id(user_id=found_user.uu_id):
|
||||
for key in already_tokens:
|
||||
token_user = json.loads(redis_cli.get(key) or {})
|
||||
for key, token_user in already_tokens.items():
|
||||
redis_cli.delete(key)
|
||||
selected_user = Users.filter_one(
|
||||
Users.uu_id == token_user.get("uu_id"),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import json
|
||||
import typing
|
||||
from typing import Union
|
||||
|
||||
|
|
@ -36,7 +35,6 @@ from api_validations.validations_request import (
|
|||
EmployeeSelection,
|
||||
)
|
||||
from api_services import (
|
||||
password_is_changed_template,
|
||||
change_your_password_template,
|
||||
save_access_token_to_redis,
|
||||
update_selected_to_redis,
|
||||
|
|
@ -66,13 +64,11 @@ class AuthenticationLoginEventMethods(MethodToEvent):
|
|||
request: Request,
|
||||
):
|
||||
access_dict = Users.login_user_with_credentials(data=data, request=request)
|
||||
found_user = access_dict.get("user", None)
|
||||
if not found_user:
|
||||
if not access_dict.get("user", None):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials"
|
||||
)
|
||||
access_object = access_dict.get("access_object")
|
||||
if not access_object:
|
||||
if not access_dict.get("access_object", None):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="This User has no active role registered. Please contact your administrator.",
|
||||
|
|
@ -84,7 +80,7 @@ class AuthenticationLoginEventMethods(MethodToEvent):
|
|||
"access_token": access_dict.get("access_token"),
|
||||
"refresh_token": access_dict.get("refresher_token"),
|
||||
"access_object": access_dict.get("access_object"),
|
||||
"user": found_user.get_dict(),
|
||||
"user": access_dict.get("user", None).get_dict(),
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
|
|
@ -263,7 +259,7 @@ class AuthenticationCheckTokenEventMethods(MethodToEvent):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def authentication_login_with_domain_and_creds(
|
||||
def authentication_check_token_is_valid(
|
||||
cls,
|
||||
request,
|
||||
):
|
||||
|
|
@ -329,28 +325,27 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
|
|||
def authentication_change_password(
|
||||
cls,
|
||||
data: ChangePassword,
|
||||
token_dict: typing.Union[EmployeeSelection, OccupantSelection],
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
if token_dict.user_type == 1:
|
||||
if found_user := Users.filter_one(
|
||||
Users.uu_id == token_dict.person_uu_id,
|
||||
).data:
|
||||
if found_user.check_password(data.old_password):
|
||||
found_user.set_password(data.new_password)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Password is changed successfully",
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
if found_user := Users.filter_one(
|
||||
Users.id == token_dict.user_id,
|
||||
).data:
|
||||
if found_user.check_password(data.old_password):
|
||||
found_user.create_password(found_user=found_user, password=data.new_password)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": False,
|
||||
"message": "Old password is not correct",
|
||||
"completed": True,
|
||||
"message": "Password is changed successfully",
|
||||
},
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": False,
|
||||
"message": "Old password is not correct",
|
||||
},
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={"completed": False, "message": "Invalid data"},
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
|
|
@ -405,6 +400,56 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
|
|||
)
|
||||
|
||||
|
||||
class AuthenticationResetPasswordEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "UPDATE"
|
||||
__event_keys__ = {
|
||||
"af9e121e-24bb-44ac-a616-471d5754360e": "authentication_reset_password",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def authentication_reset_password(
|
||||
cls,
|
||||
data: Forgot
|
||||
):
|
||||
from sqlalchemy import or_
|
||||
|
||||
found_user = Users.query.filter(
|
||||
or_(
|
||||
Users.email == str(data.access_key).lower(),
|
||||
Users.phone_number == str(data.access_key).replace(" ", ""),
|
||||
),
|
||||
).first()
|
||||
if not found_user:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Given access key or domain is not matching with the any user record.",
|
||||
)
|
||||
|
||||
reset_password_token = found_user.reset_password_token()
|
||||
send_email_completed = send_email(
|
||||
subject=f"Dear {found_user.user_tag}, a password reset request has been received.",
|
||||
receivers=[str(found_user.email)],
|
||||
html=change_your_password_template(
|
||||
user_name=found_user.user_tag,
|
||||
forgot_link=ApiStatic.forgot_link(forgot_key=reset_password_token),
|
||||
),
|
||||
)
|
||||
if not send_email_completed:
|
||||
raise found_user.raise_http_exception(
|
||||
status_code=400,
|
||||
message="Email can not be sent. Try again later"
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Password is created successfully",
|
||||
"data": found_user.get_dict(),
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
|
||||
|
||||
class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "UPDATE"
|
||||
|
|
@ -432,12 +477,10 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
|||
status_code=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
if already_tokens := get_object_via_user_uu_id(user_id=found_user.uu_id):
|
||||
for key in already_tokens:
|
||||
token_user = json.loads(redis_cli.get(key) or {})
|
||||
for key, token_user in already_tokens.items():
|
||||
redis_cli.delete(key)
|
||||
selected_user = Users.filter_one(
|
||||
Users.uu_id == token_user.get("uu_id"),
|
||||
*Users.valid_record_args(Users),
|
||||
)
|
||||
selected_user.remove_refresher_token(
|
||||
domain=data.domain, disconnect=True
|
||||
|
|
@ -493,13 +536,12 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
|
|||
status_code=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
token_users = get_object_via_user_uu_id(token_dict.user_uu_id)
|
||||
for token_user in token_users:
|
||||
if token_dict.domain == data.domain:
|
||||
redis_cli.delete(token_user)
|
||||
for token, token_user in token_users.items():
|
||||
if token_user['domain'] == data.domain:
|
||||
selected_user = Users.filter_one(
|
||||
Users.uu_id == token_user.get("uu_id"),
|
||||
*Users.valid_record_args(Users),
|
||||
)
|
||||
Users.uu_id == token_dict.user_uu_id,
|
||||
).data
|
||||
redis_cli.delete(token)
|
||||
selected_user.remove_refresher_token(domain=data.domain)
|
||||
# UserLogger.log_error(
|
||||
# str(
|
||||
|
|
@ -720,6 +762,9 @@ AuthenticationChangePasswordEventMethod = AuthenticationChangePasswordEventMetho
|
|||
AuthenticationCreatePasswordEventMethod = AuthenticationCreatePasswordEventMethods(
|
||||
action=ActionsSchema(endpoint="/authentication/create_password")
|
||||
)
|
||||
AuthenticationResetPasswordEventMethod = AuthenticationResetPasswordEventMethods(
|
||||
action=ActionsSchema(endpoint="/authentication/reset_password")
|
||||
)
|
||||
AuthenticationDisconnectUserEventMethod = AuthenticationDisconnectUserEventMethods(
|
||||
action=ActionsSchema(endpoint="/authentication/disconnect")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
|||
BuildParts.build_id == token_dict.selected_occupant.build_id,
|
||||
BuildParts.active == True,
|
||||
).data
|
||||
print("occupants_build_part", occupants_build_part)
|
||||
if not occupants_build_part:
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@ import typing
|
|||
from fastapi import status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from api_configs import ApiStatic
|
||||
from databases import MongoQueryIdentity, Users, Companies, People
|
||||
from databases.no_sql_models.validations import DomainViaUser
|
||||
|
||||
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
|
||||
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
from api_validations.core_response import AlchemyJsonResponse
|
||||
|
||||
|
||||
from api_services.email.service import send_email
|
||||
from api_services.templates.password_templates import change_your_password_template
|
||||
from api_validations.validations_request import (
|
||||
InsertUsers,
|
||||
UpdateUsers,
|
||||
|
|
@ -87,6 +87,20 @@ class UserCreateEventMethods(MethodToEvent):
|
|||
company_uuid=created_user.related_company,
|
||||
)
|
||||
mongo_query_identity.create_domain_via_user(payload=domain_via_user)
|
||||
reset_password_token = created_user.reset_password_token()
|
||||
send_email_completed = send_email(
|
||||
subject=f"Dear {created_user.user_tag}, your password has been changed.",
|
||||
receivers=[str(created_user.email)],
|
||||
html=change_your_password_template(
|
||||
user_name=created_user.user_tag,
|
||||
forgot_link=ApiStatic.forgot_link(forgot_key=reset_password_token),
|
||||
),
|
||||
)
|
||||
if not send_email_completed:
|
||||
raise created_user.raise_http_exception(
|
||||
status_code=400,
|
||||
message="Email can not be sent. Try again later"
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class AuthDefaultEventBlock(AddEventFunctionality):
|
|||
{"function_code": "c90f3334-10c9-4181-b5ff-90d98a0287b2"},
|
||||
{"function_code": "e3ca6e24-b9f8-4127-949c-3bfa364e3513"},
|
||||
{"function_code": "c140cd5f-307f-4046-a93e-3ade032a57a7"},
|
||||
{"function_code": "af9e121e-24bb-44ac-a616-471d5754360e"},
|
||||
]
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -13,10 +13,11 @@ def send_email(
|
|||
) -> bool:
|
||||
try:
|
||||
email_sender.connect()
|
||||
receivers = ["karatay@mehmetkaratay.com.tr"]
|
||||
email_sender.send(
|
||||
subject=subject,
|
||||
receivers=receivers,
|
||||
text=text,
|
||||
text=text + f" : Gonderilen [{str(receivers)}]",
|
||||
html=html,
|
||||
cc=cc,
|
||||
bcc=bcc,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ from api_services.redis.functions import (
|
|||
get_object_via_user_uu_id,
|
||||
get_object_via_access_key,
|
||||
)
|
||||
from databases.sql_models.building.build import Build
|
||||
from databases.sql_models.identity.identity import Addresses, OccupantTypes
|
||||
|
||||
|
||||
def save_object_to_redis(
|
||||
|
|
@ -55,13 +57,11 @@ def save_access_token_to_redis(
|
|||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=dict(message="User is not found."),
|
||||
# headers=json.loads(json.dumps(request.headers)),
|
||||
)
|
||||
|
||||
# Check user is already logged in or has a previous session
|
||||
already_tokens = get_object_via_user_uu_id(user_id=found_user.uu_id)
|
||||
for key in already_tokens or []:
|
||||
token_user = json.loads(redis_cli.get(key).decode() or {})
|
||||
for key, token_user in already_tokens.items():
|
||||
if token_user.get("domain", "") == domain:
|
||||
redis_cli.delete(key)
|
||||
|
||||
|
|
@ -79,7 +79,6 @@ def save_access_token_to_redis(
|
|||
detail=dict(
|
||||
message="NO Living Space is found. This user has no proper account set please contact the admin."
|
||||
),
|
||||
# headers=json.loads(json.dumps(request.headers)),
|
||||
)
|
||||
occupants_selection_dict = {}
|
||||
for living_space in living_spaces:
|
||||
|
|
@ -92,19 +91,38 @@ def save_access_token_to_redis(
|
|||
detail=dict(
|
||||
message="No build Part is found for the living space. Please contact the admin."
|
||||
),
|
||||
# headers=json.loads(json.dumps(request.headers)),
|
||||
)
|
||||
build_part = build_parts_selection.get(1)
|
||||
|
||||
occupant_dict = {
|
||||
"uu_id": str(living_space.occupant_type_uu_id),
|
||||
"id": living_space.occupant_type,
|
||||
}
|
||||
if not str(build_part.uu_id) in occupants_selection_dict:
|
||||
occupants_selection_dict[str(build_part.uu_id)] = [occupant_dict]
|
||||
elif str(build_part.uu_id) in occupants_selection_dict:
|
||||
occupants_selection_dict[str(build_part.uu_id)].append(occupant_dict)
|
||||
|
||||
build = build_part.buildings
|
||||
occupant_type = OccupantTypes.filter_by_one(
|
||||
id=living_space.occupant_type,
|
||||
system=True,
|
||||
).data
|
||||
if not str(build.uu_id) in occupants_selection_dict:
|
||||
occupants_selection_dict[str(build.uu_id)] = dict(
|
||||
build_uu_id=str(build.uu_id),
|
||||
build_name=build.build_name,
|
||||
build_no=build.build_no,
|
||||
occupants=[
|
||||
dict(
|
||||
part_uu_id=str(build_part.uu_id),
|
||||
part_name=build_part.part_name,
|
||||
part_level=build_part.part_level,
|
||||
uu_id=str(occupant_type.uu_id),
|
||||
description=occupant_type.occupant_description,
|
||||
code=occupant_type.occupant_code
|
||||
)
|
||||
]
|
||||
)
|
||||
elif str(build.uu_id) in occupants_selection_dict:
|
||||
occupants_selection_dict[str(build.uu_id)]["occupants"].append(dict(
|
||||
part_uu_id=str(build_part.uu_id),
|
||||
part_name=build_part.part_name,
|
||||
part_level=build_part.part_level,
|
||||
uu_id=str(occupant_type.uu_id),
|
||||
description=occupant_type.occupant_description,
|
||||
code=occupant_type.occupant_code
|
||||
))
|
||||
save_object_to_redis(
|
||||
access_token=access_token,
|
||||
model_object=OccupantTokenObject(
|
||||
|
|
@ -119,21 +137,15 @@ def save_access_token_to_redis(
|
|||
available_occupants=occupants_selection_dict,
|
||||
),
|
||||
)
|
||||
new_occupants_selection_dict = {}
|
||||
for key, value in occupants_selection_dict.items():
|
||||
new_occupants_selection_dict[key] = [
|
||||
occupant.get("uu_id") for occupant in value
|
||||
]
|
||||
|
||||
return dict(
|
||||
user_type=UserType.occupant.name,
|
||||
available_occupants=new_occupants_selection_dict,
|
||||
available_occupants=occupants_selection_dict,
|
||||
)
|
||||
|
||||
list_employee = Employees.filter_all(
|
||||
Employees.people_id == found_user.person_id,
|
||||
).data
|
||||
companies_uu_id_list, companies_id_list = [], []
|
||||
companies_uu_id_list, companies_id_list, companies_list = [], [], []
|
||||
duty_uu_id_list, duty_id_list = [], []
|
||||
for employee in list_employee:
|
||||
staff = Staff.filter_one(Staff.id == employee.staff_id).data
|
||||
|
|
@ -150,6 +162,13 @@ def save_access_token_to_redis(
|
|||
).data:
|
||||
companies_uu_id_list.append(str(company.uu_id))
|
||||
companies_id_list.append(company.id)
|
||||
company_address = Addresses.filter_by_one(id=company.official_address_id).data
|
||||
companies_list.append(dict(
|
||||
uu_id=str(company.uu_id),
|
||||
public_name=company.public_name,
|
||||
company_type=company.company_type,
|
||||
company_address=company_address,
|
||||
))
|
||||
|
||||
save_object_to_redis(
|
||||
access_token=access_token,
|
||||
|
|
@ -170,7 +189,7 @@ def save_access_token_to_redis(
|
|||
)
|
||||
return dict(
|
||||
user_type=UserType.employee.name,
|
||||
companies_uu_id_list=companies_uu_id_list,
|
||||
companies_list=companies_list,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -62,9 +62,12 @@ def get_object_via_access_key(
|
|||
)
|
||||
|
||||
|
||||
def get_object_via_user_uu_id(user_id: str) -> typing.Union[list, None]:
|
||||
def get_object_via_user_uu_id(user_id: str) -> typing.Union[dict, None]:
|
||||
already_tokens = redis_cli.scan_iter(match=str("*:" + str(user_id)))
|
||||
already_tokens = list(already_tokens)
|
||||
if list(already_tokens):
|
||||
return list(already_tokens)
|
||||
return None
|
||||
already_tokens_list, already_tokens_dict = [], {}
|
||||
for already_token in already_tokens:
|
||||
redis_object = json.loads(redis_cli.get(already_token) or {})
|
||||
already_tokens_list.append(redis_object)
|
||||
already_tokens_dict[already_token.decode()] = redis_object
|
||||
return already_tokens_dict
|
||||
|
||||
|
|
|
|||
|
|
@ -157,6 +157,8 @@ def password_is_changed_template(**kwargs):
|
|||
return template
|
||||
|
||||
|
||||
|
||||
|
||||
def invalid_ip_or_address_found(**kwargs):
|
||||
user_name, current_year, address = (
|
||||
kwargs["user_name"],
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ from pydantic import BaseModel
|
|||
|
||||
|
||||
class ChangePassword(BaseModelRegular):
|
||||
domain_name: str
|
||||
access_key: str
|
||||
old_password: str
|
||||
new_password: str
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from databases.no_sql_models.validations import (
|
|||
from api_library.date_time_actions.date_functions import system_arrow, client_arrow
|
||||
from api_configs import ApiStatic, Auth
|
||||
|
||||
from api_services.redis.auth_actions.auth import save_access_token_to_redis
|
||||
|
||||
|
||||
|
||||
class PasswordModule:
|
||||
|
|
@ -168,12 +168,12 @@ class AuthModule(PasswordModule):
|
|||
Auth.REFRESHER_TOKEN_LENGTH
|
||||
)
|
||||
found_user.save()
|
||||
return found_user.password_token
|
||||
|
||||
def generate_refresher_token(self, domain: str, remember_me=False):
|
||||
from databases import (
|
||||
UsersTokens,
|
||||
)
|
||||
|
||||
if remember_me:
|
||||
refresh_token = self.generate_token(Auth.REFRESHER_TOKEN_LENGTH)
|
||||
if already_token := UsersTokens.filter_by_one(
|
||||
|
|
@ -183,13 +183,20 @@ class AuthModule(PasswordModule):
|
|||
already_token.expires_at = system_arrow.shift(days=3)
|
||||
already_token.save()
|
||||
return refresh_token
|
||||
UsersTokens.create(
|
||||
users_tokens = UsersTokens.filter_by_all(
|
||||
user_id=self.id, token_type="RememberMe", domain=domain, system=True
|
||||
).data
|
||||
if users_tokens:
|
||||
users_tokens.query.delete()
|
||||
UsersTokens.save()
|
||||
|
||||
users_token = UsersTokens.find_or_create(
|
||||
user_id=self.id,
|
||||
token_type="RememberMe",
|
||||
token=refresh_token,
|
||||
domain=domain,
|
||||
)
|
||||
UsersTokens.save()
|
||||
users_token.save_and_confirm()
|
||||
return refresh_token
|
||||
return None
|
||||
|
||||
|
|
@ -204,6 +211,7 @@ class UserLoginModule(AuthModule):
|
|||
|
||||
@classmethod
|
||||
def login_user_with_credentials(cls, data, request):
|
||||
from api_services.redis.auth_actions.auth import save_access_token_to_redis
|
||||
from databases import (
|
||||
Users,
|
||||
People,
|
||||
|
|
|
|||
|
|
@ -479,7 +479,7 @@ class BuildParts(CrudCollection):
|
|||
@property
|
||||
def part_name(self):
|
||||
if build_type := BuildTypes.filter_by_one(
|
||||
system=True, id=self.build_part_type_id
|
||||
system=True, id=self.part_type_id
|
||||
).data:
|
||||
return f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}"
|
||||
return f"Undefined:{str(build_type.type_name).upper()}"
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ services:
|
|||
|
||||
commercial_mongo_service:
|
||||
container_name: commercial_mongo_service
|
||||
# image: "bitnami/mongodb:latest"
|
||||
image: "bitnami/mongodb:4.4.1-debian-10-r3"
|
||||
image: "bitnami/mongodb:latest"
|
||||
# image: "bitnami/mongodb:4.4.1-debian-10-r3"
|
||||
networks:
|
||||
- network_store_services
|
||||
environment:
|
||||
|
|
@ -61,90 +61,90 @@ services:
|
|||
- "41575:41575"
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- wag_management_init_service
|
||||
- grafana
|
||||
# depends_on:
|
||||
# - wag_management_init_service
|
||||
# - grafana
|
||||
|
||||
wag_management_service_second:
|
||||
container_name: wag_management_service_second
|
||||
restart: on-failure
|
||||
build:
|
||||
context: .
|
||||
dockerfile: service_app/Dockerfile
|
||||
ports:
|
||||
- "41576:41575"
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- wag_management_init_service
|
||||
- grafana
|
||||
|
||||
wag_management_init_service:
|
||||
container_name: wag_management_init_service
|
||||
build:
|
||||
context: .
|
||||
dockerfile: service_app_init/Dockerfile
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- postgres_commercial
|
||||
|
||||
wag_bank_services:
|
||||
container_name: wag_bank_services
|
||||
restart: on-failure
|
||||
build:
|
||||
context: .
|
||||
dockerfile: service_app_banks/mailService.Dockerfile
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- postgres_commercial
|
||||
environment:
|
||||
- DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
|
||||
- PYTHONPATH=/service_app_banks
|
||||
|
||||
wag_account_services:
|
||||
container_name: wag_account_services
|
||||
restart: on-failure
|
||||
build:
|
||||
context: .
|
||||
dockerfile: service_account_records/account.Dockerfile
|
||||
networks:
|
||||
- network_store_services
|
||||
depends_on:
|
||||
- postgres_commercial
|
||||
environment:
|
||||
- DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
|
||||
- PYTHONPATH=/
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus
|
||||
container_name: prometheus
|
||||
ports:
|
||||
- "9090:9090"
|
||||
volumes:
|
||||
- ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
command:
|
||||
- '--config.file=/etc/prometheus/prometheus.yml'
|
||||
networks:
|
||||
- network_store_services
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana
|
||||
container_name: grafana
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- prometheus
|
||||
networks:
|
||||
- network_store_services
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_USER=admin
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
- GF_USERS_ALLOW_SIGN_UP=false
|
||||
- GF_USERS_ALLOW_ORG_CREATE=false
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
# wag_management_service_second:
|
||||
# container_name: wag_management_service_second
|
||||
# restart: on-failure
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: service_app/Dockerfile
|
||||
# ports:
|
||||
# - "41576:41575"
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# depends_on:
|
||||
# - wag_management_init_service
|
||||
# - grafana
|
||||
#
|
||||
# wag_management_init_service:
|
||||
# container_name: wag_management_init_service
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: service_app_init/Dockerfile
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# depends_on:
|
||||
# - postgres_commercial
|
||||
#
|
||||
# wag_bank_services:
|
||||
# container_name: wag_bank_services
|
||||
# restart: on-failure
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: service_app_banks/mailService.Dockerfile
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# depends_on:
|
||||
# - postgres_commercial
|
||||
# environment:
|
||||
# - DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
|
||||
# - PYTHONPATH=/service_app_banks
|
||||
#
|
||||
# wag_account_services:
|
||||
# container_name: wag_account_services
|
||||
# restart: on-failure
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: service_account_records/account.Dockerfile
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# depends_on:
|
||||
# - postgres_commercial
|
||||
# environment:
|
||||
# - DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
|
||||
# - PYTHONPATH=/
|
||||
#
|
||||
# prometheus:
|
||||
# image: prom/prometheus
|
||||
# container_name: prometheus
|
||||
# ports:
|
||||
# - "9090:9090"
|
||||
# volumes:
|
||||
# - ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
# command:
|
||||
# - '--config.file=/etc/prometheus/prometheus.yml'
|
||||
# networks:
|
||||
# - network_store_services
|
||||
#
|
||||
# grafana:
|
||||
# image: grafana/grafana
|
||||
# container_name: grafana
|
||||
# ports:
|
||||
# - "3030:3000"
|
||||
# depends_on:
|
||||
# - prometheus
|
||||
# networks:
|
||||
# - network_store_services
|
||||
# environment:
|
||||
# - GF_SECURITY_ADMIN_USER=admin
|
||||
# - GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
# - GF_USERS_ALLOW_SIGN_UP=false
|
||||
# - GF_USERS_ALLOW_ORG_CREATE=false
|
||||
# volumes:
|
||||
# - grafana_data:/var/lib/grafana
|
||||
|
||||
# wag_management_test_service:
|
||||
# container_name: wag_management_test_service
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from api_events.events import (
|
|||
AuthenticationRefreshEventMethod,
|
||||
AuthenticationChangePasswordEventMethod,
|
||||
AuthenticationCreatePasswordEventMethod,
|
||||
AuthenticationResetPasswordEventMethod,
|
||||
AuthenticationDisconnectUserEventMethod,
|
||||
AuthenticationLogoutEventMethod,
|
||||
AuthenticationRefreshTokenEventMethod,
|
||||
|
|
@ -55,88 +56,79 @@ def authentication_login_with_domain_and_creds(request: Request, data: Login):
|
|||
|
||||
@login_route.get(path="/valid", summary="Check access token is valid")
|
||||
def authentication_check_token_is_valid(request: Request):
|
||||
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
active_function = getattr(
|
||||
AuthenticationCheckTokenEventMethod, "authentication_check_token_is_valid"
|
||||
return AuthenticationCheckTokenEventMethod.authentication_check_token_is_valid(
|
||||
request=request
|
||||
)
|
||||
return active_function(request=request, token_dict=token_dict)
|
||||
|
||||
|
||||
@login_route.get(path="/refresh", summary="Refresh credentials with access token")
|
||||
def authentication_refresh_user_info(request: Request):
|
||||
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
active_function = getattr(
|
||||
AuthenticationRefreshEventMethod, "authentication_refresh_user_info"
|
||||
return AuthenticationRefreshEventMethod.authentication_refresh_user_info(
|
||||
request=request, token_dict=token_dict
|
||||
)
|
||||
return active_function(request=request, token_dict=token_dict)
|
||||
|
||||
|
||||
@login_route.post(path="/change_password", summary="Change password with access token")
|
||||
def authentication_change_password(request: Request, data: ChangePassword):
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
active_function = getattr(
|
||||
AuthenticationChangePasswordEventMethod, "authentication_change_password"
|
||||
return AuthenticationChangePasswordEventMethod.authentication_change_password(
|
||||
data=data, token_dict=token_dict
|
||||
)
|
||||
return active_function(data=data, token_dict=token_dict)
|
||||
|
||||
|
||||
@login_route.post(
|
||||
path="/create_password", summary="Create password with password token"
|
||||
)
|
||||
def authentication_create_password(data: CreatePassword):
|
||||
active_function = getattr(
|
||||
AuthenticationCreatePasswordEventMethod, "authentication_create_password"
|
||||
return AuthenticationCreatePasswordEventMethod.authentication_create_password(
|
||||
data=data
|
||||
)
|
||||
|
||||
@login_route.post(
|
||||
path="/reset_password", summary="Create password with password token"
|
||||
)
|
||||
def authentication_reset_password(data: Forgot):
|
||||
return AuthenticationResetPasswordEventMethod.authentication_reset_password(
|
||||
data=data
|
||||
)
|
||||
return active_function(data=data)
|
||||
|
||||
|
||||
@login_route.post(path="/disconnect", summary="Disconnect user with access token")
|
||||
def authentication_disconnect_user(request: Request, data: Logout):
|
||||
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
active_function = getattr(
|
||||
AuthenticationDisconnectUserEventMethod, "authentication_disconnect_user"
|
||||
return AuthenticationDisconnectUserEventMethod.authentication_disconnect_user(
|
||||
data=data, request=request, token_dict=token_dict
|
||||
)
|
||||
return active_function(data=data, request=request, token_dict=token_dict)
|
||||
|
||||
|
||||
@login_route.post(path="/logout", summary="Logout user with access token")
|
||||
def authentication_logout_user(request: Request, data: Logout):
|
||||
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
active_function = getattr(
|
||||
AuthenticationLogoutEventMethod, "authentication_logout_user"
|
||||
return AuthenticationLogoutEventMethod.authentication_logout_user(
|
||||
data=data, token_dict=token_dict
|
||||
)
|
||||
return active_function(data=data, request=request, token_dict=token_dict)
|
||||
|
||||
|
||||
@login_route.post(path="/refresher", summary="Refresh token with refresh token")
|
||||
def authentication_refresher_token(request: Request, data: Remember):
|
||||
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
active_function = getattr(
|
||||
AuthenticationRefreshTokenEventMethod, "authentication_refresher_token"
|
||||
return AuthenticationRefreshTokenEventMethod.authentication_refresher_token(
|
||||
data=data, request=request, token_dict=token_dict
|
||||
)
|
||||
return active_function(data=data, request=request, token_dict=token_dict)
|
||||
|
||||
|
||||
@login_route.post(path="/forgot", summary="Forgot password with email or phone number")
|
||||
def authentication_forgot_password(request: Request, data: Forgot):
|
||||
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
active_function = getattr(
|
||||
AuthenticationForgotPasswordEventMethod, "authentication_forgot_password"
|
||||
return AuthenticationForgotPasswordEventMethod.authentication_forgot_password(
|
||||
data=data, request=request, token_dict=token_dict
|
||||
)
|
||||
return active_function(data=data, request=request, token_dict=token_dict)
|
||||
|
||||
|
||||
@login_route.post(path="/avatar", summary="Get link of avatar with credentials")
|
||||
def authentication_download_avatar(request: Request, data: Forgot):
|
||||
|
||||
token_dict = parse_token_object_to_dict(request=request)
|
||||
active_function = getattr(
|
||||
AuthenticationDownloadAvatarEventMethod, "authentication_download_avatar"
|
||||
return AuthenticationDownloadAvatarEventMethod.authentication_download_avatar(
|
||||
data=data, request=request, token_dict=token_dict
|
||||
)
|
||||
return active_function(data=data, request=request, token_dict=token_dict)
|
||||
|
|
|
|||
Loading…
Reference in New Issue