예제 #1
0
 def initialize(self, *a, **kw):
     """Retrieve the user-cookier on every new page-load."""
     webapp2.RequestHandler.initialize(self, *a, **kw)
     username = self.read_secure_cookie('user')
     if username:
         self.user = UserEntity.by_name(username)  # noqa
     else:
         self.user = False  # noqa
예제 #2
0
 def test_UserEntity_register(self):
     """UserEntity.register should create the account, with correct data."""
     UserEntity.register(username='******', password='******').put()
     user = UserEntity.gql("WHERE username = '******'")[0]
     user2 = UserEntity.by_name('Jamie')
     user3 = UserEntity.by_name('Kelly')
     self.assertEqual(user.username, 'Jamie',
                      'gql-query should return a user.')
     self.assertEqual(
         user2.username, 'Jamie',
         'UserEntity.by_name should return a user for username.')
     self.assertEqual(
         user3, None,
         'UserEntity.by_name should return None if the user does not exist')
     self.assertNotEqual(
         user.password, 'password123',
         'userpassword should be hashed, not stored as plain text')
     self.assertEqual(len(user.password), 60,
                      'userpassword should be hashed to 60 characters')
예제 #3
0
 def render(self, template, **kw):
     """Helper function for rendering templates."""
     username = self.read_secure_cookie('user')
     kw['signed_in'] = username
     kw['user'] = UserEntity.by_name(username)
     self.write(self.render_str(template, **kw))