/// <summary> /// 注销当前用户 /// </summary> public static void LogOut() { DateTime exTime = DateTime.Now.AddDays(-1);//过期时间 //写入cookie EncryptCookies.SetCookies(CookieConfig.UserIdCkName, "", exTime); //userid EncryptCookies.SetCookies(CookieConfig.StampCkName, "", exTime); //时间戳 EncryptCookies.SetCookies(CookieConfig.TokenCkName, "", exTime); //密令 EncryptCookies.SetCookies(CookieConfig.UserOther, "", exTime); //userinfo }
/// <summary> /// 刷新cookie中用户信息 /// </summary> /// <param name="userId"></param> public static void RefreshCookieUserInfo(int userId) { var vmodel = UserInfoToVModel(GetUserInfo(userId)); if (vmodel != null) { vmodel.Password = string.Empty; //密码要保密啊 vmodel.RName = Roles.GetRoleInfo(vmodel.RoleId).RName; //角色名 DateTime exTime = DateTime.Now.AddMilliseconds(CookieConfig.LoginCookieExpiredTime); //过期时间 //写入其它信息 EncryptCookies.SetCookies(CookieConfig.UserOther, JsonConvert.SerializeObject(vmodel), exTime); //userinfo } }
/// <summary> /// 登录成功写入用户信息 /// </summary> /// <param name="userInfo"></param> public static void Login(UserInfo userInfo) { long stamp = DateTimeHelper.GetTimeStamp(); IToken token = new LoginToken(userInfo.Id.ToString(CultureInfo.InvariantCulture), stamp, TokenConfig.LoginTokenKey); //密令 DateTime exTime = DateTime.Now.AddMilliseconds(CookieConfig.LoginCookieExpiredTime); //过期时间 //写入cookie EncryptCookies.SetCookies(CookieConfig.UserIdCkName, userInfo.Id.ToString(CultureInfo.InvariantCulture), exTime); //userid EncryptCookies.SetCookies(CookieConfig.StampCkName, stamp.ToString(CultureInfo.InvariantCulture), exTime); //时间戳 EncryptCookies.SetCookies(CookieConfig.TokenCkName, token.GetToken(), exTime); //密令 var vmodel = UserInfoToVModel(userInfo); vmodel.Password = string.Empty; //密码要保密啊 vmodel.RName = Roles.GetRoleInfo(vmodel.RoleId).RName; //角色名 //写入其它信息 EncryptCookies.SetCookies(CookieConfig.UserOther, JsonConvert.SerializeObject(vmodel), exTime);//userinfo }