public static UserViewModel GetUserFromSessoin() { HttpSessionState session = HttpContext.Current.Session; if (session["userName"] != null && session["pwd"] != null) { UserViewModel u = new UserViewModel(); u.UserName = session["userName"].ToString(); u.Password = session["pwd"].ToString(); return u; } else return null; }
public static void SetUserToSessoin(UserViewModel user) { HttpSessionState session = HttpContext.Current.Session; session["userName"] = user.UserName; session["pwd"] = user.Password; }
public static void ClearUserFromSession(UserViewModel user) { HttpSessionState session = HttpContext.Current.Session; session.Remove("userName"); session.Remove("pwd"); }
public async Task<ActionResult> Login(UserViewModel uv) { CoreTask ct = await CoreTaskManager.GetCoreTask(uv.UserName, uv.Password, new MessageListUI()); if (ct != null) { UserViewModel.SetUserToSessoin(uv); string u = uv.UserName; long d = DateTime.Now.Ticks; string k = CoreTaskManager.md5(uv.UserName + d + "hehehe"); Response.Cookies.Add(new HttpCookie("u", u)); Response.Cookies.Add(new HttpCookie("d", d.ToString())); Response.Cookies.Add(new HttpCookie("k", k)); await ct.instance.Login(); return new RedirectResult("/Core"); ; } else { ViewBag.Msg = "权限已经完全开放,然而你的账号密码错误"; return View(); } }