def test_comment_login_logout(self): user = ("test_" + generate_random()).lower() pwd = "pwd123" rv = self.login(user, pwd) self.assertEqual(200, rv.status_code) self.assertIn(b"No valid username found", rv.data) exec_createuser(user, pwd) rv = self.login(user, pwd) data = rv.get_json() self.assertIsInstance(data, dict) self.assertIn("sid", data) self.assertIn("code", data) self.assertIn("expire", data) self.assertEqual(data["code"], 0) with self.app.test_request_context(): self.app.preprocess_request() (signin, userinfo) = default_login_auth(data["sid"]) self.assertTrue(signin) self.assertIsInstance(userinfo, dict) self.assertEqual(user, userinfo["username"]) rv = self.client.get("/api/config") self.assertEqual(405, rv.status_code) rv = self.client.post("/api/config") self.assertEqual(403, rv.status_code) self.logout() rv = self.client.post("/api/config") self.assertEqual(404, rv.status_code)
def before_request(): g.signin, g.userinfo = default_login_auth() #: No Required field g.site = get_site_config() g.cfg = Attribute(g.site) #: Required field: username, is_admin g.userinfo = Attribute(g.userinfo) g.is_admin = is_true(g.userinfo.is_admin)
def before_request(): g.rc = rc g.signin, g.userinfo = default_login_auth() #: Trigger hook, you can modify flask.g hm.call("before_request") #: No Required field g.site = get_site_config() g.cfg = Attribute(g.site) #: Required field: username, is_admin g.userinfo = Attribute(g.userinfo) g.is_admin = is_true(g.userinfo.is_admin)
def before_request(): g.rc = rc g.site = get_site_config() g.cfg = Attribute(g.site) g.signin, g.userinfo = default_login_auth() #: Trigger hook, you can modify flask.g hm.call("before_request") #: (Logged-on state)required field: username, is_admin g.userinfo = Attribute(change_userinfo(g.userinfo)) g.is_admin = is_true(g.userinfo.is_admin) g.next = get_redirect_url()