def create_access_token(self): """ 创建client token, 用于rest api常用验证 """ r = self.auth_rest_token() if r == "secret_token": client_token = { "token": self.encode_auth_token()["token"], "expiration": time.time() + get_config( "rest_auth_token", "REST_ACCESS_TOKEN_LIFETIME")} sid = rest_session.set("access_token", client_token) if sid: data = { "client_id": sid, "access_token": client_token["token"]} else: data = {"msg": gettext("Failed to get, please try again"), "msg_type": "w", "custom_status": 400} else: data = { "msg": gettext("The OSR-RestToken provided by the request header is not a SecretToken"), "msg_type": "w", "custom_status": 400} return data
def language_set(): lan = request.argget.all('language', "zh_CN") session["language"] = lan if request.headers.get('OSR-ClientId'): rest_session.set("language", lan) else: session["language"] = lan if lan in list(get_config('babel', 'LANGUAGES').keys()): data = {"msg_type":"s", "msg":gettext("Set up language success"), "http_status":201} else: data = {"msg_type": "e", "msg": gettext("Does not support this language"), "http_status": 400} return data