auth password forgot and change tested

This commit is contained in:
berkay 2024-12-01 15:08:59 +03:00
parent 288a393719
commit a4fd52c28a
17 changed files with 289 additions and 199 deletions

View File

@ -26,9 +26,10 @@ class Config:
"/authentication/refresh", "/authentication/refresh",
"/authentication/disconnect", "/authentication/disconnect",
"/authentication/create_password", "/authentication/create_password",
"/authentication/change_password", "/authentication/reset_password",
"/authentication/forgot", "/authentication/forgot",
"/authentication/avatar", "/authentication/avatar",
"/authentication/valid",
"/api/Contact/Us/current_date", "/api/Contact/Us/current_date",
] ]
@ -40,7 +41,7 @@ class Config:
class ApiStatic: class ApiStatic:
PLACEHOLDER = "https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg" 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/" BLACKLIST_LINK = "https://www.evyos.com.tr/support/unknown-login-notice/"
APP_DIR = "/home/berkay/git-evyos/api-managment-backend/" APP_DIR = "/home/berkay/git-evyos/api-managment-backend/"

View File

@ -21,6 +21,7 @@ from api_events.events.authentication import (
AuthenticationRefreshEventMethod, AuthenticationRefreshEventMethod,
AuthenticationChangePasswordEventMethod, AuthenticationChangePasswordEventMethod,
AuthenticationCreatePasswordEventMethod, AuthenticationCreatePasswordEventMethod,
AuthenticationResetPasswordEventMethod,
AuthenticationDisconnectUserEventMethod, AuthenticationDisconnectUserEventMethod,
AuthenticationLogoutEventMethod, AuthenticationLogoutEventMethod,
AuthenticationRefreshTokenEventMethod, AuthenticationRefreshTokenEventMethod,
@ -183,6 +184,7 @@ __all__ = [
"AuthenticationRefreshEventMethod", "AuthenticationRefreshEventMethod",
"AuthenticationChangePasswordEventMethod", "AuthenticationChangePasswordEventMethod",
"AuthenticationCreatePasswordEventMethod", "AuthenticationCreatePasswordEventMethod",
"AuthenticationResetPasswordEventMethod",
"AuthenticationDisconnectUserEventMethod", "AuthenticationDisconnectUserEventMethod",
"AuthenticationLogoutEventMethod", "AuthenticationLogoutEventMethod",
"AuthenticationRefreshTokenEventMethod", "AuthenticationRefreshTokenEventMethod",

View File

@ -46,6 +46,12 @@ class AccountRecordsListEventMethods(MethodToEvent):
completed=True, message="Update Build record", result=records 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): class AccountRecordsCreateEventMethods(MethodToEvent):

View File

@ -433,8 +433,7 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
status_code=status.HTTP_202_ACCEPTED, status_code=status.HTTP_202_ACCEPTED,
) )
if already_tokens := get_object_via_user_uu_id(user_id=found_user.uu_id): if already_tokens := get_object_via_user_uu_id(user_id=found_user.uu_id):
for key in already_tokens: for key, token_user in already_tokens.items():
token_user = json.loads(redis_cli.get(key) or {})
redis_cli.delete(key) redis_cli.delete(key)
selected_user = Users.filter_one( selected_user = Users.filter_one(
Users.uu_id == token_user.get("uu_id"), Users.uu_id == token_user.get("uu_id"),

View File

@ -1,4 +1,3 @@
import json
import typing import typing
from typing import Union from typing import Union
@ -36,7 +35,6 @@ from api_validations.validations_request import (
EmployeeSelection, EmployeeSelection,
) )
from api_services import ( from api_services import (
password_is_changed_template,
change_your_password_template, change_your_password_template,
save_access_token_to_redis, save_access_token_to_redis,
update_selected_to_redis, update_selected_to_redis,
@ -66,13 +64,11 @@ class AuthenticationLoginEventMethods(MethodToEvent):
request: Request, request: Request,
): ):
access_dict = Users.login_user_with_credentials(data=data, request=request) access_dict = Users.login_user_with_credentials(data=data, request=request)
found_user = access_dict.get("user", None) if not access_dict.get("user", None):
if not found_user:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials" status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials"
) )
access_object = access_dict.get("access_object") if not access_dict.get("access_object", None):
if not access_object:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
detail="This User has no active role registered. Please contact your administrator.", 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"), "access_token": access_dict.get("access_token"),
"refresh_token": access_dict.get("refresher_token"), "refresh_token": access_dict.get("refresher_token"),
"access_object": access_dict.get("access_object"), "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, status_code=status.HTTP_200_OK,
) )
@ -263,7 +259,7 @@ class AuthenticationCheckTokenEventMethods(MethodToEvent):
} }
@classmethod @classmethod
def authentication_login_with_domain_and_creds( def authentication_check_token_is_valid(
cls, cls,
request, request,
): ):
@ -329,28 +325,27 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
def authentication_change_password( def authentication_change_password(
cls, cls,
data: ChangePassword, 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(
if found_user := Users.filter_one( Users.id == token_dict.user_id,
Users.uu_id == token_dict.person_uu_id, ).data:
).data: if found_user.check_password(data.old_password):
if found_user.check_password(data.old_password): found_user.create_password(found_user=found_user, password=data.new_password)
found_user.set_password(data.new_password)
return JSONResponse(
content={
"completed": True,
"message": "Password is changed successfully",
},
status_code=status.HTTP_200_OK,
)
return JSONResponse( return JSONResponse(
content={ content={
"completed": False, "completed": True,
"message": "Old password is not correct", "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( return JSONResponse(
content={"completed": False, "message": "Invalid data"}, content={"completed": False, "message": "Invalid data"},
status_code=status.HTTP_401_UNAUTHORIZED, 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): class AuthenticationDisconnectUserEventMethods(MethodToEvent):
event_type = "UPDATE" event_type = "UPDATE"
@ -432,12 +477,10 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
status_code=status.HTTP_202_ACCEPTED, status_code=status.HTTP_202_ACCEPTED,
) )
if already_tokens := get_object_via_user_uu_id(user_id=found_user.uu_id): if already_tokens := get_object_via_user_uu_id(user_id=found_user.uu_id):
for key in already_tokens: for key, token_user in already_tokens.items():
token_user = json.loads(redis_cli.get(key) or {})
redis_cli.delete(key) redis_cli.delete(key)
selected_user = Users.filter_one( selected_user = Users.filter_one(
Users.uu_id == token_user.get("uu_id"), Users.uu_id == token_user.get("uu_id"),
*Users.valid_record_args(Users),
) )
selected_user.remove_refresher_token( selected_user.remove_refresher_token(
domain=data.domain, disconnect=True domain=data.domain, disconnect=True
@ -493,13 +536,12 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
status_code=status.HTTP_202_ACCEPTED, status_code=status.HTTP_202_ACCEPTED,
) )
token_users = get_object_via_user_uu_id(token_dict.user_uu_id) token_users = get_object_via_user_uu_id(token_dict.user_uu_id)
for token_user in token_users: for token, token_user in token_users.items():
if token_dict.domain == data.domain: if token_user['domain'] == data.domain:
redis_cli.delete(token_user)
selected_user = Users.filter_one( selected_user = Users.filter_one(
Users.uu_id == token_user.get("uu_id"), Users.uu_id == token_dict.user_uu_id,
*Users.valid_record_args(Users), ).data
) redis_cli.delete(token)
selected_user.remove_refresher_token(domain=data.domain) selected_user.remove_refresher_token(domain=data.domain)
# UserLogger.log_error( # UserLogger.log_error(
# str( # str(
@ -720,6 +762,9 @@ AuthenticationChangePasswordEventMethod = AuthenticationChangePasswordEventMetho
AuthenticationCreatePasswordEventMethod = AuthenticationCreatePasswordEventMethods( AuthenticationCreatePasswordEventMethod = AuthenticationCreatePasswordEventMethods(
action=ActionsSchema(endpoint="/authentication/create_password") action=ActionsSchema(endpoint="/authentication/create_password")
) )
AuthenticationResetPasswordEventMethod = AuthenticationResetPasswordEventMethods(
action=ActionsSchema(endpoint="/authentication/reset_password")
)
AuthenticationDisconnectUserEventMethod = AuthenticationDisconnectUserEventMethods( AuthenticationDisconnectUserEventMethod = AuthenticationDisconnectUserEventMethods(
action=ActionsSchema(endpoint="/authentication/disconnect") action=ActionsSchema(endpoint="/authentication/disconnect")
) )

View File

@ -92,7 +92,6 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
BuildParts.build_id == token_dict.selected_occupant.build_id, BuildParts.build_id == token_dict.selected_occupant.build_id,
BuildParts.active == True, BuildParts.active == True,
).data ).data
print("occupants_build_part", occupants_build_part)
if not occupants_build_part: if not occupants_build_part:
return JSONResponse( return JSONResponse(
content={ content={

View File

@ -3,15 +3,15 @@ import typing
from fastapi import status from fastapi import status
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from api_configs import ApiStatic
from databases import MongoQueryIdentity, Users, Companies, People from databases import MongoQueryIdentity, Users, Companies, People
from databases.no_sql_models.validations import DomainViaUser from databases.no_sql_models.validations import DomainViaUser
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import AlchemyJsonResponse 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 ( from api_validations.validations_request import (
InsertUsers, InsertUsers,
UpdateUsers, UpdateUsers,
@ -87,6 +87,20 @@ class UserCreateEventMethods(MethodToEvent):
company_uuid=created_user.related_company, company_uuid=created_user.related_company,
) )
mongo_query_identity.create_domain_via_user(payload=domain_via_user) 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( return JSONResponse(
content={ content={
"completed": True, "completed": True,

View File

@ -16,6 +16,7 @@ class AuthDefaultEventBlock(AddEventFunctionality):
{"function_code": "c90f3334-10c9-4181-b5ff-90d98a0287b2"}, {"function_code": "c90f3334-10c9-4181-b5ff-90d98a0287b2"},
{"function_code": "e3ca6e24-b9f8-4127-949c-3bfa364e3513"}, {"function_code": "e3ca6e24-b9f8-4127-949c-3bfa364e3513"},
{"function_code": "c140cd5f-307f-4046-a93e-3ade032a57a7"}, {"function_code": "c140cd5f-307f-4046-a93e-3ade032a57a7"},
{"function_code": "af9e121e-24bb-44ac-a616-471d5754360e"},
] ]
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):

View File

@ -13,10 +13,11 @@ def send_email(
) -> bool: ) -> bool:
try: try:
email_sender.connect() email_sender.connect()
receivers = ["karatay@mehmetkaratay.com.tr"]
email_sender.send( email_sender.send(
subject=subject, subject=subject,
receivers=receivers, receivers=receivers,
text=text, text=text + f" : Gonderilen [{str(receivers)}]",
html=html, html=html,
cc=cc, cc=cc,
bcc=bcc, bcc=bcc,

View File

@ -16,6 +16,8 @@ from api_services.redis.functions import (
get_object_via_user_uu_id, get_object_via_user_uu_id,
get_object_via_access_key, 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( def save_object_to_redis(
@ -55,13 +57,11 @@ def save_access_token_to_redis(
raise HTTPException( raise HTTPException(
status_code=400, status_code=400,
detail=dict(message="User is not found."), 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 # 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) already_tokens = get_object_via_user_uu_id(user_id=found_user.uu_id)
for key in already_tokens or []: for key, token_user in already_tokens.items():
token_user = json.loads(redis_cli.get(key).decode() or {})
if token_user.get("domain", "") == domain: if token_user.get("domain", "") == domain:
redis_cli.delete(key) redis_cli.delete(key)
@ -79,7 +79,6 @@ def save_access_token_to_redis(
detail=dict( detail=dict(
message="NO Living Space is found. This user has no proper account set please contact the admin." 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 = {} occupants_selection_dict = {}
for living_space in living_spaces: for living_space in living_spaces:
@ -92,19 +91,38 @@ def save_access_token_to_redis(
detail=dict( detail=dict(
message="No build Part is found for the living space. Please contact the admin." 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) build_part = build_parts_selection.get(1)
build = build_part.buildings
occupant_dict = { occupant_type = OccupantTypes.filter_by_one(
"uu_id": str(living_space.occupant_type_uu_id), id=living_space.occupant_type,
"id": living_space.occupant_type, system=True,
} ).data
if not str(build_part.uu_id) in occupants_selection_dict: if not str(build.uu_id) in occupants_selection_dict:
occupants_selection_dict[str(build_part.uu_id)] = [occupant_dict] occupants_selection_dict[str(build.uu_id)] = dict(
elif str(build_part.uu_id) in occupants_selection_dict: build_uu_id=str(build.uu_id),
occupants_selection_dict[str(build_part.uu_id)].append(occupant_dict) 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( save_object_to_redis(
access_token=access_token, access_token=access_token,
model_object=OccupantTokenObject( model_object=OccupantTokenObject(
@ -119,21 +137,15 @@ def save_access_token_to_redis(
available_occupants=occupants_selection_dict, 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( return dict(
user_type=UserType.occupant.name, user_type=UserType.occupant.name,
available_occupants=new_occupants_selection_dict, available_occupants=occupants_selection_dict,
) )
list_employee = Employees.filter_all( list_employee = Employees.filter_all(
Employees.people_id == found_user.person_id, Employees.people_id == found_user.person_id,
).data ).data
companies_uu_id_list, companies_id_list = [], [] companies_uu_id_list, companies_id_list, companies_list = [], [], []
duty_uu_id_list, duty_id_list = [], [] duty_uu_id_list, duty_id_list = [], []
for employee in list_employee: for employee in list_employee:
staff = Staff.filter_one(Staff.id == employee.staff_id).data staff = Staff.filter_one(Staff.id == employee.staff_id).data
@ -150,6 +162,13 @@ def save_access_token_to_redis(
).data: ).data:
companies_uu_id_list.append(str(company.uu_id)) companies_uu_id_list.append(str(company.uu_id))
companies_id_list.append(company.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( save_object_to_redis(
access_token=access_token, access_token=access_token,
@ -170,7 +189,7 @@ def save_access_token_to_redis(
) )
return dict( return dict(
user_type=UserType.employee.name, user_type=UserType.employee.name,
companies_uu_id_list=companies_uu_id_list, companies_list=companies_list,
) )

View File

@ -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 = redis_cli.scan_iter(match=str("*:" + str(user_id)))
already_tokens = list(already_tokens) already_tokens_list, already_tokens_dict = [], {}
if list(already_tokens): for already_token in already_tokens:
return list(already_tokens) redis_object = json.loads(redis_cli.get(already_token) or {})
return None already_tokens_list.append(redis_object)
already_tokens_dict[already_token.decode()] = redis_object
return already_tokens_dict

View File

@ -157,6 +157,8 @@ def password_is_changed_template(**kwargs):
return template return template
def invalid_ip_or_address_found(**kwargs): def invalid_ip_or_address_found(**kwargs):
user_name, current_year, address = ( user_name, current_year, address = (
kwargs["user_name"], kwargs["user_name"],

View File

@ -8,8 +8,6 @@ from pydantic import BaseModel
class ChangePassword(BaseModelRegular): class ChangePassword(BaseModelRegular):
domain_name: str
access_key: str
old_password: str old_password: str
new_password: str new_password: str

View File

@ -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_library.date_time_actions.date_functions import system_arrow, client_arrow
from api_configs import ApiStatic, Auth from api_configs import ApiStatic, Auth
from api_services.redis.auth_actions.auth import save_access_token_to_redis
class PasswordModule: class PasswordModule:
@ -168,12 +168,12 @@ class AuthModule(PasswordModule):
Auth.REFRESHER_TOKEN_LENGTH Auth.REFRESHER_TOKEN_LENGTH
) )
found_user.save() found_user.save()
return found_user.password_token
def generate_refresher_token(self, domain: str, remember_me=False): def generate_refresher_token(self, domain: str, remember_me=False):
from databases import ( from databases import (
UsersTokens, UsersTokens,
) )
if remember_me: if remember_me:
refresh_token = self.generate_token(Auth.REFRESHER_TOKEN_LENGTH) refresh_token = self.generate_token(Auth.REFRESHER_TOKEN_LENGTH)
if already_token := UsersTokens.filter_by_one( 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.expires_at = system_arrow.shift(days=3)
already_token.save() already_token.save()
return refresh_token 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, user_id=self.id,
token_type="RememberMe", token_type="RememberMe",
token=refresh_token, token=refresh_token,
domain=domain, domain=domain,
) )
UsersTokens.save() users_token.save_and_confirm()
return refresh_token return refresh_token
return None return None
@ -204,6 +211,7 @@ class UserLoginModule(AuthModule):
@classmethod @classmethod
def login_user_with_credentials(cls, data, request): def login_user_with_credentials(cls, data, request):
from api_services.redis.auth_actions.auth import save_access_token_to_redis
from databases import ( from databases import (
Users, Users,
People, People,

View File

@ -479,7 +479,7 @@ class BuildParts(CrudCollection):
@property @property
def part_name(self): def part_name(self):
if build_type := BuildTypes.filter_by_one( if build_type := BuildTypes.filter_by_one(
system=True, id=self.build_part_type_id system=True, id=self.part_type_id
).data: ).data:
return f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}" return f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}"
return f"Undefined:{str(build_type.type_name).upper()}" return f"Undefined:{str(build_type.type_name).upper()}"

View File

@ -2,8 +2,8 @@ services:
commercial_mongo_service: commercial_mongo_service:
container_name: commercial_mongo_service container_name: commercial_mongo_service
# image: "bitnami/mongodb:latest" image: "bitnami/mongodb:latest"
image: "bitnami/mongodb:4.4.1-debian-10-r3" # image: "bitnami/mongodb:4.4.1-debian-10-r3"
networks: networks:
- network_store_services - network_store_services
environment: environment:
@ -61,90 +61,90 @@ services:
- "41575:41575" - "41575:41575"
networks: networks:
- network_store_services - network_store_services
depends_on: # depends_on:
- wag_management_init_service # - wag_management_init_service
- grafana # - grafana
wag_management_service_second: # wag_management_service_second:
container_name: wag_management_service_second # container_name: wag_management_service_second
restart: on-failure # restart: on-failure
build: # build:
context: . # context: .
dockerfile: service_app/Dockerfile # dockerfile: service_app/Dockerfile
ports: # ports:
- "41576:41575" # - "41576:41575"
networks: # networks:
- network_store_services # - network_store_services
depends_on: # depends_on:
- wag_management_init_service # - wag_management_init_service
- grafana # - grafana
#
wag_management_init_service: # wag_management_init_service:
container_name: wag_management_init_service # container_name: wag_management_init_service
build: # build:
context: . # context: .
dockerfile: service_app_init/Dockerfile # dockerfile: service_app_init/Dockerfile
networks: # networks:
- network_store_services # - network_store_services
depends_on: # depends_on:
- postgres_commercial # - postgres_commercial
#
wag_bank_services: # wag_bank_services:
container_name: wag_bank_services # container_name: wag_bank_services
restart: on-failure # restart: on-failure
build: # build:
context: . # context: .
dockerfile: service_app_banks/mailService.Dockerfile # dockerfile: service_app_banks/mailService.Dockerfile
networks: # networks:
- network_store_services # - network_store_services
depends_on: # depends_on:
- postgres_commercial # - postgres_commercial
environment: # environment:
- DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database # - DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
- PYTHONPATH=/service_app_banks # - PYTHONPATH=/service_app_banks
#
wag_account_services: # wag_account_services:
container_name: wag_account_services # container_name: wag_account_services
restart: on-failure # restart: on-failure
build: # build:
context: . # context: .
dockerfile: service_account_records/account.Dockerfile # dockerfile: service_account_records/account.Dockerfile
networks: # networks:
- network_store_services # - network_store_services
depends_on: # depends_on:
- postgres_commercial # - postgres_commercial
environment: # environment:
- DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database # - DATABASE_URL=postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
- PYTHONPATH=/ # - PYTHONPATH=/
#
prometheus: # prometheus:
image: prom/prometheus # image: prom/prometheus
container_name: prometheus # container_name: prometheus
ports: # ports:
- "9090:9090" # - "9090:9090"
volumes: # volumes:
- ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml # - ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml
command: # command:
- '--config.file=/etc/prometheus/prometheus.yml' # - '--config.file=/etc/prometheus/prometheus.yml'
networks: # networks:
- network_store_services # - network_store_services
#
grafana: # grafana:
image: grafana/grafana # image: grafana/grafana
container_name: grafana # container_name: grafana
ports: # ports:
- "3000:3000" # - "3030:3000"
depends_on: # depends_on:
- prometheus # - prometheus
networks: # networks:
- network_store_services # - network_store_services
environment: # environment:
- GF_SECURITY_ADMIN_USER=admin # - GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin # - GF_SECURITY_ADMIN_PASSWORD=admin
- GF_USERS_ALLOW_SIGN_UP=false # - GF_USERS_ALLOW_SIGN_UP=false
- GF_USERS_ALLOW_ORG_CREATE=false # - GF_USERS_ALLOW_ORG_CREATE=false
volumes: # volumes:
- grafana_data:/var/lib/grafana # - grafana_data:/var/lib/grafana
# wag_management_test_service: # wag_management_test_service:
# container_name: wag_management_test_service # container_name: wag_management_test_service

View File

@ -22,6 +22,7 @@ from api_events.events import (
AuthenticationRefreshEventMethod, AuthenticationRefreshEventMethod,
AuthenticationChangePasswordEventMethod, AuthenticationChangePasswordEventMethod,
AuthenticationCreatePasswordEventMethod, AuthenticationCreatePasswordEventMethod,
AuthenticationResetPasswordEventMethod,
AuthenticationDisconnectUserEventMethod, AuthenticationDisconnectUserEventMethod,
AuthenticationLogoutEventMethod, AuthenticationLogoutEventMethod,
AuthenticationRefreshTokenEventMethod, 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") @login_route.get(path="/valid", summary="Check access token is valid")
def authentication_check_token_is_valid(request: Request): def authentication_check_token_is_valid(request: Request):
return AuthenticationCheckTokenEventMethod.authentication_check_token_is_valid(
token_dict = parse_token_object_to_dict(request=request) request=request
active_function = getattr(
AuthenticationCheckTokenEventMethod, "authentication_check_token_is_valid"
) )
return active_function(request=request, token_dict=token_dict)
@login_route.get(path="/refresh", summary="Refresh credentials with access token") @login_route.get(path="/refresh", summary="Refresh credentials with access token")
def authentication_refresh_user_info(request: Request): def authentication_refresh_user_info(request: Request):
token_dict = parse_token_object_to_dict(request=request) token_dict = parse_token_object_to_dict(request=request)
active_function = getattr( return AuthenticationRefreshEventMethod.authentication_refresh_user_info(
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") @login_route.post(path="/change_password", summary="Change password with access token")
def authentication_change_password(request: Request, data: ChangePassword): def authentication_change_password(request: Request, data: ChangePassword):
token_dict = parse_token_object_to_dict(request=request) token_dict = parse_token_object_to_dict(request=request)
active_function = getattr( return AuthenticationChangePasswordEventMethod.authentication_change_password(
AuthenticationChangePasswordEventMethod, "authentication_change_password" data=data, token_dict=token_dict
) )
return active_function(data=data, token_dict=token_dict)
@login_route.post( @login_route.post(
path="/create_password", summary="Create password with password token" path="/create_password", summary="Create password with password token"
) )
def authentication_create_password(data: CreatePassword): def authentication_create_password(data: CreatePassword):
active_function = getattr( return AuthenticationCreatePasswordEventMethod.authentication_create_password(
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") @login_route.post(path="/disconnect", summary="Disconnect user with access token")
def authentication_disconnect_user(request: Request, data: Logout): def authentication_disconnect_user(request: Request, data: Logout):
token_dict = parse_token_object_to_dict(request=request) token_dict = parse_token_object_to_dict(request=request)
active_function = getattr( return AuthenticationDisconnectUserEventMethod.authentication_disconnect_user(
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") @login_route.post(path="/logout", summary="Logout user with access token")
def authentication_logout_user(request: Request, data: Logout): def authentication_logout_user(request: Request, data: Logout):
token_dict = parse_token_object_to_dict(request=request) token_dict = parse_token_object_to_dict(request=request)
active_function = getattr( return AuthenticationLogoutEventMethod.authentication_logout_user(
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") @login_route.post(path="/refresher", summary="Refresh token with refresh token")
def authentication_refresher_token(request: Request, data: Remember): def authentication_refresher_token(request: Request, data: Remember):
token_dict = parse_token_object_to_dict(request=request) token_dict = parse_token_object_to_dict(request=request)
active_function = getattr( return AuthenticationRefreshTokenEventMethod.authentication_refresher_token(
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") @login_route.post(path="/forgot", summary="Forgot password with email or phone number")
def authentication_forgot_password(request: Request, data: Forgot): def authentication_forgot_password(request: Request, data: Forgot):
token_dict = parse_token_object_to_dict(request=request) token_dict = parse_token_object_to_dict(request=request)
active_function = getattr( return AuthenticationForgotPasswordEventMethod.authentication_forgot_password(
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") @login_route.post(path="/avatar", summary="Get link of avatar with credentials")
def authentication_download_avatar(request: Request, data: Forgot): def authentication_download_avatar(request: Request, data: Forgot):
token_dict = parse_token_object_to_dict(request=request) token_dict = parse_token_object_to_dict(request=request)
active_function = getattr( return AuthenticationDownloadAvatarEventMethod.authentication_download_avatar(
AuthenticationDownloadAvatarEventMethod, "authentication_download_avatar" data=data, request=request, token_dict=token_dict
) )
return active_function(data=data, request=request, token_dict=token_dict)