def index_view(context, request): username = request.session.get('username', '') result = {'username': username} if username == '': result['admin'] = False else: result['admin'] = True if 'group:admin' in User.by_username(username, request).groups else False return result
def test_by_username(self): from papaye.models import User from papaye.factories import user_root_factory root = user_root_factory(self.request) root['a_user'] = User('a_user', 'password') result = User.by_username('a_user', self.request) self.assertIsInstance(result, User) self.assertEqual(result.username, 'a_user')
def auth_check_func(username, password, request): user = User.by_username(username, request) if user and user.password_verify(password): return user.groups return None
def test_by_username_without_result(self): from papaye.models import User result = User.by_username('a_user', self.request) self.assertIsNone(result)