def login(session: SessionModel): url = getserviceUrl(session.host, session.port, "user", "login") headers = defaultRequestHeader() res = post(url, headers=headers, json={"user": session.user, "password": session.password}) session.token = res["token"] session.userid = res["userid"] return session
def inner_func(session: SessionModel, service, api, json, **kwargs): url = getserviceUrl(session.host, session.port, service, api) headers = defaultRequestHeader() headers["hku_token"] = session.token r = put(url, json=json, headers=headers, **kwargs) if "update_token" in r: session.token = r["update_token"] return r
def login(session: SessionModel): url = getserviceUrl(session.host, session.port, "user", "login") headers = defaultRequestHeader() sha = hashlib.sha256() sha.update(bytes(session.password, encoding='utf8')) pwd = sha.hexdigest() res = post(url, headers=headers, json={ "user": session.user, "password": pwd }) if res["result"]: session.token = res["token"] session.userid = res["userid"] else: raise RestfulError(res) return session