Esempio n. 1
0
def test_reset_user_password(user_factory):
    with patch('szurubooru.func.auth.create_password'), \
            patch('szurubooru.func.auth.get_password_hash'):
        user = user_factory()
        auth.create_password.return_value = 'salt'
        auth.get_password_hash.return_value = 'hash'
        users.reset_user_password(user)
        assert user.password_salt == 'salt'
        assert user.password_hash == 'hash'
Esempio n. 2
0
def test_reset_user_password(user_factory):
    with patch('szurubooru.func.auth.create_password'), \
            patch('szurubooru.func.auth.get_password_hash'):
        user = user_factory()
        auth.create_password.return_value = 'salt'
        auth.get_password_hash.return_value = 'hash'
        users.reset_user_password(user)
        assert user.password_salt == 'salt'
        assert user.password_hash == 'hash'
Esempio n. 3
0
def test_reset_user_password(user_factory):
    with patch("szurubooru.func.auth.create_password"), patch(
            "szurubooru.func.auth.get_password_hash"):
        user = user_factory()
        auth.create_password.return_value = "salt"
        auth.get_password_hash.return_value = ("hash", 3)
        users.reset_user_password(user)
        assert user.password_salt == "salt"
        assert user.password_hash == "hash"
        assert user.password_revision == 3
Esempio n. 4
0
 def post(self, ctx, user_name):
     ''' Verify token from mail, generate a new password and return it. '''
     user = users.get_user_by_name_or_email(user_name)
     good_token = auth.generate_authentication_token(user)
     token = ctx.get_param_as_string('token', required=True)
     if token != good_token:
         raise errors.ValidationError('Invalid password reset token.')
     new_password = users.reset_user_password(user)
     ctx.session.commit()
     return {'password': new_password}
Esempio n. 5
0
def finish_password_reset(ctx, params):
    ''' Verify token from mail, generate a new password and return it. '''
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    good_token = auth.generate_authentication_token(user)
    token = ctx.get_param_as_string('token', required=True)
    if token != good_token:
        raise errors.ValidationError('Invalid password reset token.')
    new_password = users.reset_user_password(user)
    versions.bump_version(user)
    ctx.session.commit()
    return {'password': new_password}
Esempio n. 6
0
def finish_password_reset(ctx: rest.Context,
                          params: Dict[str, str]) -> rest.Response:
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    good_token = auth.generate_authentication_token(user)
    token = ctx.get_param_as_string('token')
    if _hash(token) != _hash(good_token):
        raise errors.ValidationError('Invalid password reset token.')
    new_password = users.reset_user_password(user)
    versions.bump_version(user)
    ctx.session.commit()
    return {'password': new_password}
Esempio n. 7
0
def finish_password_reset(
        ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    user_name = params['user_name']
    user = users.get_user_by_name_or_email(user_name)
    good_token = auth.generate_authentication_token(user)
    token = ctx.get_param_as_string('token')
    if _hash(token) != _hash(good_token):
        raise errors.ValidationError('Invalid password reset token.')
    new_password = users.reset_user_password(user)
    versions.bump_version(user)
    ctx.session.commit()
    return {'password': new_password}