Beispiel #1
0
    def test_cached_auth(self):
        user = User(email='*****@*****.**', password='******')
        user.save()

        self.assertTrue(check_user('*****@*****.**', '123456')[1])

        user.password = '******'
        user.save()

        self.assertFalse(check_user('*****@*****.**', '123456')[1])

        self.assertTrue(check_user('*****@*****.**', 'lero')[1])
Beispiel #2
0
    def decorated(*args, **kwargs):
        auth = request.authorization

        if not auth:
            raise Unauthorized('Basic auth required.')

        email = auth['username']
        password = auth['password']

        id_user, valid = check_user(email, password)

        if not id_user:
            raise Unauthorized('User does not exist.')

        if not valid:
            raise Unauthorized('Invalid user or password.')

        g.id_user = id_user
        g.valid = valid

        return f(*args, **kwargs)