def create_account( email: str, password: str, birthdate: date, has_allowed_recommendations: bool = False, is_email_validated: bool = False, send_activation_mail: bool = True, ) -> User: if find_user_by_email(email): raise exceptions.UserAlreadyExistsException() user = User( email=format_email(email), dateOfBirth=datetime.combine(birthdate, datetime.min.time()), isEmailValidated=is_email_validated, departementCode="007", publicName=VOID_PUBLIC_NAME, # Required because model validation requires 3+ chars hasSeenTutorials=False, firstName=VOID_FIRST_NAME, hasAllowedRecommendations=has_allowed_recommendations, ) age = user.calculate_age() if not age or age < constants.ACCOUNT_CREATION_MINIMUM_AGE: raise exceptions.UnderAgeUserException() user.setPassword(password) repository.save(user) if not is_email_validated and send_activation_mail: request_email_confirmation(user) return user
def is_user_eligible(user: User) -> bool: age = user.calculate_age() return age is not None and age == constants.ELIGIBILITY_AGE