コード例 #1
0
ファイル: filer.py プロジェクト: jlucus/electronic-filing
async def filer_info(payload: FilerContactInfoSchema,
                     user: User = Depends(get_active_user),
                     db_session: Session = Depends(get_db)):

    try:
        # user must be filer
        if user.account_type != 'filer':
            raise AccountPermissionException()

        filer = await get_filer_by_user_id(db_session, user.id)
        if filer is None:
            raise AccountPermissionException()

        # get filer types
        ftypes = [x.filer_type for x in filer.filer_types]

        # blocker filer types
        blockers = ['candidate', 'campaign']
        blocked = False
        for blocker in blockers:
            if blocker in ftypes:
                blocked = True
                break

        if blocked:
            raise Http400("Filer cannot change contact info. "\
                          "Please contact City Clerk's Office.")

        if payload.effective_date is None or not is_valid_date(
                payload.effective_date):
            payload.effective_date = today()

        res = await update_filer_contact_info(db_session, filer, payload)
        if res:
            user.first_name = payload.first_name
            user.last_name = payload.last_name
            user.middle_name = payload.middle_name
            db_session.commit()

        return {"success": res}

    except AccountPermissionException as e:
        # we don't log this
        raise

    except Exception as e:
        logger.exception(traceback.format_exc())
        handle_exc(e)

    return None
コード例 #2
0
async def reset_password_request(
        payload: ResetPasswordRequest,
        db_session: Session = Depends(get_db),
):

    try:
        res = await check_recaptcha_response(payload.recaptcha)

        if ENFORCE_RECAPTCHA and res is False:
            Http400(detail="Recaptcha validation failed.")

        res = await user_password_reset_request(db_session, payload)

        return {"success": True}

    except AccountException:
        raise

    except Exception as e:
        logger.exception(traceback.format_exc())
        handle_exc(e)
コード例 #3
0
ファイル: user.py プロジェクト: jlucus/electronic-filing
async def set_user_password(db_session: Session, payload: UserResetPassword):

    res = check_access_token(payload)
    logger.info(f"Reset password: {res}")

    if 'sub' not in res.keys() or 'email_code' not in res.keys():
        raise Http400(detail="Missing user information in token.")

    user_email = res['sub']
    email_code = res['email_code']

    user = get_user_by_email(db_session, user_email)

    if user is None:
        logger.info(f"User {email} does not exist. Password reset fail.")
        return True

    if not user.active:
        # user isn't active
        logger.info(f"User {email} is inactive. Password reset fail.")
        raise AccountException(detail="User is not active. "\
                               "Please contact City Clerk's Office.")

    if user.city:
        logger.info(f"User {email} is City user. Password reset fail.")
        raise AccountException(
            detail="sandiego.gov passwords cannot be reset here.")

    if user.password_set_reset_secret != email_code:
        logger.info(f"User {email} wrong reset code. Password reset fail.")
        raise Http401(detail="Invalid credentials.")

    hashed_password = get_password_hash(payload.password)
    user.password_hash = hashed_password

    db_session.commit()

    return True