Exemplo n.º 1
0
    def run(self, discriminator):
        with self.__data_handler__ as repo:
            if isinstance(discriminator, UUID) or is_UUID(discriminator):
                user = repo.get_by_id(model.User, discriminator)
            elif isinstance(discriminator, str):
                user = repo.get_user_by_username(discriminator)
                if user is None:
                    user = repo.get_user_by_Email(discriminator)
                else:
                    raise ValidationException(
                        f'input value for discriminator is not valid = {discriminator}'
                    )
            if user:
                user_entity = self.__model_translator__.user_translator(user)

                person_entity = None
                if user.Persons:
                    person_entity = [
                        self.__model_translator__.person_translator(person)
                        for person in user.Persons
                    ]
                    if user.Persons.__len__() == 1:
                        user_entity.__current_person__ = self.__model_translator__.person_translator(
                            user.Persons[0])
                    elif user.Persons.__len__() > 1 and user.CurrentPersonId:
                        current_person = user.Persons.find(
                            Id=user.CurrentPersonId)
                        user_entity.__current_person__ = self.__model_translator__.person_translator(
                            current_person)

                return user_entity, person_entity
        return None
Exemplo n.º 2
0
def registration_validation(user: RegistrationInfo):
    if not user.email and not user.cellphone:
        raise ValidationException(
            ResourceManager.translate(Texts.USER_NEED_CONTACT))
    if user.email:
        user.cellphone.read(extract_numbers(str(user.cellphone)))
        email_validation(user.email)
    if user.cellphone:
        cellphone_validation(user.cellphone)
 def run(self, person:Person):
     if not person.user or not person.user.uid:
         raise ValidationException('user is missing!')
     person_model = self.__entity_translator__.person_translator(person, None, None)
     with self.__data_handler__ as repo:
         user = repo.get_by_id(model.User, person.user.uid)
         person_model.User = user
         person_model.UserId = user.uid
         repo.insert(person_model)
         return person_model.uid
Exemplo n.º 4
0
 def run(self, discriminator):
     with self.__uow__() as uow:
         if isinstance(discriminator, bson.ObjectId):
             return self.adp(uow.user_repository.get_user(discriminator),
                             AuthInfo)
         elif isinstance(discriminator, str):
             return self.adp(
                 uow.user_repository.get_by_username(discriminator),
                 AuthInfo)
         else:
             raise ValidationException('Discriminator is not valid!')
Exemplo n.º 5
0
def username(user_name: str) -> None:
    if not username_validation(user_name):
        raise ValidationException(
            ResourceManager.translate(Texts.USER_NAME_NOT_VALID))
Exemplo n.º 6
0
def email_validation(email: Email) -> None:
    email_str = str(email).lower()
    if not email_validator(email_str):
        raise ValidationException(
            ResourceManager.translate(Texts.EMAIL_NOT_VALID))
Exemplo n.º 7
0
def cellphone_validation(cellphone: CellPhone) -> None:
    if not mobile_number_validator(str(cellphone)):
        raise ValidationException(
            ResourceManager.translate(Texts.MOBILE_NOT_VALID))
Exemplo n.º 8
0
def password_validation(password: str = None):
    if helper.password_validation(password) is not True:
        raise ValidationException(
            ResourceManager.translate(Texts.PASSWORD_VALUE_NOT_VALID))