diff --git a/data/client.js b/data/client.js index 5db587a..f167ac6 100644 --- a/data/client.js +++ b/data/client.js @@ -18,12 +18,12 @@ export class Client{ if(!session) { this.session = new Session(); }else { - this.session = session; - } - this.load_cached_cookies(); - this.current_user = {}; - this.callback={require_login: ()=>{}}; - this.load_current_user(); + this.session = session; + } + this.load_cached_cookies(); + this.current_user = {}; + this.callback={require_login: ()=>{}}; + this.load_current_user(); } load_current_user(){ var value = wx.getStorageSync('current_user'); diff --git a/data/requests.js b/data/requests.js index 1fcc2e2..b2d908f 100644 --- a/data/requests.js +++ b/data/requests.js @@ -30,16 +30,20 @@ export class Session { dataType: dataType, responseType: responseType, success: (res) => { + let cookies =[]; if ("cookies" in res) { - let cookies = res["cookies"]; - for (var i = 0; i < cookies.length; i++) { - this.set_cookie(new Cookie(cookies[i])); - } - console.log("set new cookies:"); - console.log(this.cookies); - } else { + cookies = res["cookies"]; + } else if(res.header["Set-Cookie"]){ + cookies = res.header["Set-Cookie"].replace(", ", "@@").replace(",","||").replace("@@",", ").split("||"); + }else{ console.warn("request.js: no cookies setted in this request"); } + console.log("raw_cookies", cookies); + for (var i = 0; i < cookies.length; i++) { + this.set_cookie(new Cookie(cookies[i])); + } + console.log("set new cookies:"); + console.log(this.cookies); if (typeof success == "function") { success(res); } else { diff --git a/pages/login/login.js b/pages/login/login.js index 296cb2c..8d80ceb 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -50,6 +50,8 @@ Page({ } app.client.login({login: login, password: password, autologin: 1, success:res=>{ + console.log("login success"); + console.log(res); this.save_input(); wx.navigateBack({ delta: 1