def update_user_informations(user_informations: AlterableUserInformations):
    current_user = find_user_by_id(user_informations.id)
    if user_informations.cultural_survey_id is not None:
        current_user.culturalSurveyId = user_informations.cultural_survey_id

    if user_informations.cultural_survey_filled_date is not None:
        current_user.culturalSurveyFilledDate = user_informations.cultural_survey_filled_date

    if user_informations.department_code is not None:
        current_user.departementCode = user_informations.department_code

    if user_informations.email is not None:
        current_user.email = user_informations.email

    if user_informations.last_connection_date is not None:
        current_user.lastConnectionDate = user_informations.last_connection_date

    if user_informations.needs_to_fill_cultural_survey is not None:
        current_user.needsToFillCulturalSurvey = user_informations.needs_to_fill_cultural_survey

    if user_informations.phone_number is not None:
        current_user.phoneNumber = user_informations.phone_number

    if user_informations.postal_code is not None:
        current_user.postalCode = user_informations.postal_code

    if user_informations.public_name is not None:
        current_user.publicName = user_informations.public_name

    if user_informations.has_seen_tutorials is not None:
        current_user.hasSeenTutorials = user_informations.has_seen_tutorials
    repository.save(current_user)

    return current_user
Example #2
0
def test_change_password_failures(app):
    new_password = "******"
    user = users_factories.UserFactory()

    access_token = create_access_token(identity=user.email)
    test_client = TestClient(app.test_client())
    test_client.auth_header = {"Authorization": f"Bearer {access_token}"}

    response = test_client.post(
        "/native/v1/change_password",
        json={"currentPassword": "******", "newPassword": new_password},
    )

    assert response.status_code == 400
    assert response.json["code"] == "INVALID_PASSWORD"

    response = test_client.post(
        "/native/v1/change_password",
        json={"currentPassword": users_factories.DEFAULT_PASSWORD, "newPassword": "******"},
    )

    assert response.status_code == 400
    assert response.json["code"] == "WEAK_PASSWORD"

    user = find_user_by_id(user.id)
    assert user.password == hash_password(users_factories.DEFAULT_PASSWORD)
Example #3
0
def test_reset_password_success(app):
    new_password = "******"

    user = users_factories.UserFactory()

    token = Token(from_dict={"userId": user.id, "value": "secret-value", "type": TokenType.RESET_PASSWORD})
    repository.save(token)

    data = {"reset_password_token": token.value, "new_password": new_password}
    response = TestClient(app.test_client()).post("/native/v1/reset_password", json=data)

    user = find_user_by_id(user.id)
    assert response.status_code == 204
    assert user.password == hash_password(new_password)
Example #4
0
def test_reset_password_fail_for_password_strength(app):
    reset_token = random_token()
    user = users_factories.UserFactory(
        resetPasswordToken=reset_token,
        resetPasswordTokenValidityLimit=(datetime.utcnow() + timedelta(hours=1)),
    )
    old_password = user.password
    new_password = "******"

    data = {"reset_password_token": reset_token, "new_password": new_password}

    response = TestClient(app.test_client()).post("/native/v1/reset_password", json=data)

    user = find_user_by_id(user.id)
    assert response.status_code == 400
    assert user.password == old_password