def create_beneficiary_from_application(application_detail: dict, user: Optional[User] = None) -> User: if not user: beneficiary = User() beneficiary.password = random_password() beneficiary.email = application_detail["email"] beneficiary.dateOfBirth = application_detail["birth_date"] else: beneficiary = user beneficiary.lastName = application_detail["last_name"] beneficiary.firstName = application_detail["first_name"] beneficiary.publicName = "%s %s" % (application_detail["first_name"], application_detail["last_name"]) beneficiary.phoneNumber = application_detail["phone"] beneficiary.departementCode = application_detail["department"] beneficiary.postalCode = application_detail["postal_code"] beneficiary.civility = application_detail["civility"] beneficiary.activity = application_detail["activity"] beneficiary.isAdmin = False beneficiary.hasSeenTutorials = False generate_reset_token(beneficiary, validity_duration_hours=THIRTY_DAYS_IN_HOURS) beneficiary.isBeneficiary = True application_id = application_detail["application_id"] deposit = payments_api.create_deposit( beneficiary, f"démarches simplifiées dossier [{application_id}]") beneficiary.deposits = [deposit] return beneficiary
def post_for_password_token(body: ResetPasswordBodyModel) -> None: check_webapp_recaptcha_token( body.token, original_action="resetPassword", minimal_score=settings.RECAPTCHA_RESET_PASSWORD_MINIMAL_SCORE, ) user = find_user_by_email(body.email) if not user or not user.isActive: # Here we also return a 204 to prevent attacker from discovering which email exists in db return generate_reset_token(user) repository.save(user) is_not_pro_user = user.isBeneficiary if is_not_pro_user: try: send_reset_password_email_to_user(user) except MailServiceException as mail_service_exception: app.logger.exception( "[send_reset_password_email_to_user] " "Mail service failure", mail_service_exception) else: try: send_reset_password_email_to_pro(user) except MailServiceException as mail_service_exception: app.logger.exception( "[send_reset_password_email_to_pro] " "Mail service failure", mail_service_exception)
def to_model(beneficiary_pre_subscription: BeneficiaryPreSubscription) -> User: beneficiary = User() beneficiary.activity = beneficiary_pre_subscription.activity beneficiary.address = beneficiary_pre_subscription.address beneficiary.city = beneficiary_pre_subscription.city beneficiary.civility = beneficiary_pre_subscription.civility beneficiary.dateOfBirth = beneficiary_pre_subscription.date_of_birth beneficiary.departementCode = beneficiary_pre_subscription.department_code beneficiary.email = beneficiary_pre_subscription.email beneficiary.firstName = beneficiary_pre_subscription.first_name beneficiary.hasSeenTutorials = False beneficiary.isAdmin = False beneficiary.lastName = beneficiary_pre_subscription.last_name beneficiary.password = random_password() beneficiary.phoneNumber = beneficiary_pre_subscription.phone_number beneficiary.postalCode = beneficiary_pre_subscription.postal_code beneficiary.publicName = beneficiary_pre_subscription.public_name beneficiary.isBeneficiary = True generate_reset_token(beneficiary, validity_duration_hours=THIRTY_DAYS_IN_HOURS) deposit = payments_api.create_deposit( beneficiary, beneficiary_pre_subscription.deposit_source) beneficiary.deposits = [deposit] users_api.attach_beneficiary_import_details(beneficiary, beneficiary_pre_subscription) return beneficiary
def fulfill_user_data(user: User, deposit_source: str) -> User: user.password = random_password() generate_reset_token(user, validity_duration_hours=THIRTY_DAYS_IN_HOURS) deposit = payment_api.create_deposit(user, deposit_source) user.deposits = [deposit] return user
def on_model_change(self, form: Form, model: User, is_created: bool) -> None: if is_created: model.password = random_password() generate_reset_token(model, 24 * 14) model.publicName = f"{model.firstName} {model.lastName}" model.isBeneficiary = False model.isAdmin = False
def fill_user_from(csv_row: List[str], user: User) -> User: user.lastName = csv_row[USER_LAST_NAME_COLUMN_INDEX] user.firstName = csv_row[USER_FIRST_NAME_COLUMN_INDEX].split(" ")[0] user.publicName = "%s %s" % (user.firstName, user.lastName) user.email = csv_row[USER_EMAIL_COLUMN_INDEX] user.departementCode = csv_row[USER_DEPARTMENT_CODE_COLUMN_INDEX] user.isBeneficiary = False user.password = random_password() generate_reset_token(user, validity_duration_hours=THIRTY_DAYS_IN_HOURS) return user
def on_model_change(self, form: Form, model: User, is_created: bool) -> None: model.publicName = f"{model.firstName} {model.lastName}" if is_created: model.isBeneficiary = False model.password = random_password() generate_reset_token(model, 24 * 14) offerer = create_offerer(form) create_digital_venue(offerer) user_offerer = create_user_offerer(user=model, offerer=offerer) model.userOfferers = [user_offerer] super().on_model_change(form, model, is_created)