/// <summary> /// 判断管理员是否已经登录(解决Session超时问题) /// </summary> public bool IsAdminLogin() { //如果Session为Null if (Session[HotoKeys.SESSION_ADMIN_INFO] != null) { return(true); } else { //检查Cookies string adminname = HotoUtils.GetCookie("AdminName", "DTcms"); //解密用户名 string adminpwd = HotoUtils.GetCookie("AdminPwd", "DTcms"); if (adminname != "" && adminpwd != "") { Hoto.BLL.manager bll = new Hoto.BLL.manager(); Hoto.Model.manager model = bll.GetModel(adminname, adminpwd); if (model != null) { Session[HotoKeys.SESSION_ADMIN_INFO] = model; return(true); } } } return(false); }
/// <summary> /// 判断用户是否已经登录(解决Session超时问题) /// </summary> public bool IsUserLogin() { //如果Session为Null if (HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] != null) { return(true); } else { //检查Cookies string username = HotoUtils.GetCookie(HotoKeys.COOKIE_USER_NAME_REMEMBER, "DTcms"); //解密用户名 string password = HotoUtils.GetCookie(HotoKeys.COOKIE_USER_PWD_REMEMBER, "DTcms"); if (username != "" && password != "") { Hoto.BLL.users bll = new Hoto.BLL.users(); Hoto.Model.users model = bll.GetModel(username, password, 0); if (model != null) { HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] = model; return(true); } } } return(false); }
/// <summary> /// OnInit事件,检查用户是否已经登录 /// </summary> void UserPage_Init(object sender, EventArgs e) { turl = HotoUtils.GetCookie(HotoKeys.COOKIE_URL_REFERRER); if (string.IsNullOrEmpty(turl) || turl == HttpContext.Current.Request.Url.ToString().ToLower()) { turl = linkurl("usercenter", "index"); } if (IsUserLogin()) { //自动登录,跳转URL HttpContext.Current.Response.Redirect(turl); return; } //检查是否已授权 if (HttpContext.Current.Session["oauth_name"] == null || HttpContext.Current.Session["oauth_access_token"] == null || HttpContext.Current.Session["oauth_openid"] == null) { HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + HotoUtils.UrlEncode("登录失败,用户授权已过期,请重新登录!")); return; } Hoto.Model.user_oauth oauthModel = new Hoto.BLL.user_oauth().GetModel(HttpContext.Current.Session["oauth_name"].ToString(), HttpContext.Current.Session["oauth_openid"].ToString()); if (oauthModel != null) { //检查用户是否存在 Hoto.Model.users model = new Hoto.BLL.users().GetModel(oauthModel.user_name); if (model == null) { HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + HotoUtils.UrlEncode("登录失败,授权用户不存在或已被删除!")); return; } //记住登录状态,防止Session提前过期 HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] = model; HttpContext.Current.Session.Timeout = 45; HotoUtils.WriteCookie(HotoKeys.COOKIE_USER_NAME_REMEMBER, "DTcms", model.user_name); HotoUtils.WriteCookie(HotoKeys.COOKIE_USER_PWD_REMEMBER, "DTcms", model.password); //更新最新的Access Token oauthModel.oauth_access_token = HttpContext.Current.Session["oauth_access_token"].ToString(); new Hoto.BLL.user_oauth().Update(oauthModel); //自动登录,跳转URL HttpContext.Current.Response.Redirect(turl); return; } }
/// <summary> /// 获取cookies /// </summary> /// <returns></returns> private static string GetCookies() { return(HotoUtils.GetCookie(HotoKeys.COOKIE_SHOPPING_CART)); }