def user_from_authbasic(identifier,
                        password=None):
    errors = ApiErrors()
    errors.status_code = 401

    if identifier is None:
        errors.add_error('identifier', 'Identifier is missing.')
    if password is None:
        errors.add_error('password', 'Password is missing.')
    errors.maybe_raise()

    user = active_user_from_identifier(identifier)

    if not user:
        errors.add_error('identifier', 'Wrong identifier')
        raise errors

    if len(user.password) == 32:  # MD5 pass from Denis' platform
        if not is_hashlib_equal(password, user.password):
            errors.add_error('password', 'Wrong password')
            raise errors
        change_password(user, password, check=False)
    elif not user.check_password(password):
        errors.add_error('password', 'Wrong password')
        raise errors

    return user
Exemplo n.º 2
0
def get_user_with_credentials(identifier, password):
    errors = ApiErrors()
    errors.status_code = 401

    if identifier is None:
        errors.add_error('identifier', 'Identifier is missing.')
    if password is None:
        errors.add_error('password', 'Password is missing.')
    errors.maybe_raise()

    user = User.query.filter_by(email=identifier).first()

    if not user:
        errors.add_error('identifier', 'Wrong identifier')
        raise errors
    if not user.check_password(password):
        errors.add_error('password', 'Wrong password')
        raise errors

    return user
Exemplo n.º 3
0
def get_user_with_credentials(identifier, password):
    errors = ApiErrors()
    errors.status_code = 401

    if identifier is None:
        errors.add_error('identifier', 'Identifier is missing.')
    if password is None:
        errors.add_error('password', 'Password is missing.')
    errors.maybe_raise()

    User = get_model_with_table_name('user')
    user = User.query.filter_by(email=identifier).first()

    if not user:
        errors.add_error('identifier', 'Wrong identifier')
        raise errors
    if not user.isValidated:
        errors.add_error('identifier', "This account is not validated")
        raise errors
    if not user.check_password(password):
        errors.add_error('password', 'Wrong password')
        raise errors

    return user