def register_provider(provider: RegisterProvider, database: BlockchainDb = Depends()): aws_cognito = Cognito(os.environ['USER_POOL_ID'], os.environ['USER_POOL_WEB_CLIENT_ID']) aws_cognito.username = provider.username aws_cognito.set_base_attributes(email=provider.username, name=f'{provider.name.firstName}') aws_cognito.add_custom_attributes(usertype='provider') response = aws_cognito.register(provider.username, provider.password) for providable_treatment in provider.providableTreatments: providable_treatment.providableTreatmentId = uuid.uuid4() for address in provider.addresses: address.addressId = uuid.uuid4() try: database.commit_transaction( Provider( providerId=response['UserSub'], name=provider.name, phoneNumbers=provider.phoneNumbers, addresses=provider.addresses, dateOfBirth=provider.dateOfBirth, email=provider.email, providableTreatments=provider.providableTreatments).dict(), 'CREATE', 'Provider', 'providerId', response['UserSub']) return response['UserSub'] except: aws_cognito.delete_user() return status.HTTP_400_BAD_REQUEST
def forgot_password(user_forgot_password: ForgotPassword): aws_cognito = Cognito(os.environ['USER_POOL_ID'], os.environ['USER_POOL_WEB_CLIENT_ID']) aws_cognito.username = user_forgot_password.username aws_cognito.add_custom_attributes(email=user_forgot_password.username) aws_cognito.initiate_forgot_password()
def confirm_forgot_password( user_confirm_forgot_password: ConfirmForgotPassword): aws_cognito = Cognito(os.environ['USER_POOL_ID'], os.environ['USER_POOL_WEB_CLIENT_ID']) aws_cognito.username = user_confirm_forgot_password.username aws_cognito.add_custom_attributes( email=user_confirm_forgot_password.username) aws_cognito.confirm_forgot_password( user_confirm_forgot_password.verification_code, user_confirm_forgot_password.new_password)
def register_client(client: RegisterClient, database: BlockchainDb = Depends()): aws_cognito = Cognito(os.environ['USER_POOL_ID'], os.environ['USER_POOL_WEB_CLIENT_ID']) aws_cognito.username = client.username aws_cognito.set_base_attributes(email=client.username, name=f'{client.name.firstName}') aws_cognito.add_custom_attributes(usertype='client') response = aws_cognito.register(client.username, client.password) client.address.addressId = uuid.uuid4() database.commit_transaction( Client(clientId=response['UserSub'], name=client.name, phoneNumbers=client.phoneNumbers, address=client.address, dateOfBirth=client.dateOfBirth, email=client.email).dict(), 'CREATE', 'Client', 'clientId', response['UserSub']) return response['UserSub']