Ejemplo n.º 1
0
    def test_get_user(self):
        user1 = User(username='******', email='*****@*****.**')
        user2 = User(username='******', email='*****@*****.**')
        db.session.add(user1)
        db.session.add(user2)
        db.session.commit()

        user = backend.get_user(user1.id)
        assert user['username'] == user1.username

        users = backend.get_user([user1.id, user2.id])
        assert len(users) == 2
Ejemplo n.º 2
0
    def test_get_user(self):
        user1 = User(username='******',email='*****@*****.**')
        user2 = User(username='******',email='*****@*****.**')
        db.session.add(user1)
        db.session.add(user2)
        db.session.commit()

        user = backend.get_user(user1.id)
        assert user['username'] == user1.username

        users = backend.get_user([user1.id,user2.id])
        assert len(users) == 2
Ejemplo n.º 3
0
 def cookie_auth():
     if request.cookies.get('is_logined'):
         if authutil.is_logined(request):
             max_age = 3600*24*30*6
             expires_time = int(time.time()) + max_age
             expires = strutil.cookie_date(expires_time) 
             g.user = backend.get_user(int(request.cookie.get('ukey')))
             @after_this_request
             def set_cookie(response):
                 response.set_cookie('is_logined',
                                     'True',
                                     max_age=max_age,
                                     expires=expires,
                                     path='/')
                 return response
         else:
             g.user = {}
             @after_this_request
             def delete_cookie(response):
                 response.delete_cookie('is_logined')
                 return response
     else:
         g.user = {}