public bool AutoLogin() { try { if (AppCtx.Logined) { return(true); } var token = AppCtx.Store.Get <Token>(KEY_UserToken); if (token != null) { if (token.Created.AddSeconds(token.Expires_In / 2.0) < DateTime.Now) { token = RefreshToken(token.Refresh_Token); if (token == null) { // refresh token fail var userInfos = AppCtx.Store.GetString(KEY_UserLogin).Split(','); token = GetToken(userInfos[0], userInfos[1]); } AppCtx.Store.Set(KEY_UserToken, token); } AppCtx.SetLogind(token, GetUser()); Toast.ShowShortMsg("登录成功"); return(true); } return(false); } catch (Exception ex) { Toast.ShowShortMsg(ex.GetMessage()); return(false); } }
public bool Login(string userName, string password) { try { var token = GetToken(userName, password); if (token != null) { AppCtx.Store.SetString(KEY_UserLogin, $"{userName},{password}"); AppCtx.Store.Set(KEY_UserToken, token); AppCtx.SetLogind(token, GetUser()); Toast.ShowShortMsg("登录成功"); return(true); } return(false); } catch (Exception ex) { Toast.ShowShortMsg(ex.GetMessage()); return(false); } }