protected override void Page_Show() { if (YRequest.GetQueryString("action") == "logout") { HttpCookie admincookie = currentcontext.Request.Cookies["cmsntadmin"]; if (admincookie != null) { admincookie.Expires = DateTime.Now.AddYears(-1); currentcontext.Response.AppendCookie(admincookie); } ShowMsg("注销管理状态", "管理员登录注销成功,跳转到前台首页.", "", "index.aspx"); } UserInfo userinfo = GetUserInfo(); if (userinfo == null) { ShowError("后台登陆", "发生错误,请先登录前台,然后再访问此页.", "", "login.aspx"); } IsAdminLogined(); if (admininfo != null) { string action = YRequest.GetString("action") == string.Empty ? "default" : YRequest.GetString("action"); int id = YRequest.GetInt("id", 0); url = string.Format("frame.aspx?action={0}&id={1}", action, id); } else { url = ""; if (ispost) { //todo adminlogin string name = YRequest.GetFormString("loginname"); string password = YRequest.GetFormString("password"); string path = YRequest.GetFormString("path"); admininfo = Admins.GetAdminInfo(name, Natsuhime.Common.Utils.MD5(password)); if (admininfo != null && admininfo.Uid == userinfo.Uid) { HttpCookie admincookie = new HttpCookie("cmsntadmin"); admincookie.Values["adminid"] = admininfo.Adminid.ToString(); admincookie.Values["password"] = admininfo.Password; admincookie.Values["path"] = path; admincookie.Expires = DateTime.Now.AddMinutes(20d); currentcontext.Response.AppendCookie(admincookie); ShowMsg("后台登陆", "登录成功!开始跳转到后台首页", "", "admincp.aspx"); } else { ShowError("后台登陆", "登录失败,用户名或密码错误!", "", ""); } } } }
protected bool CheckAdminLogin() { HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["cmsnt"]; userinfo = null; if (cookie != null && cookie.Values["userid"] != null && cookie.Values["password"] != null) { int uid = Convert.ToInt32(cookie.Values["userid"]); string password = cookie.Values["password"].ToString().Trim(); if (uid > 0 && password != string.Empty) { userinfo = LiteCMS.Core.Users.GetUserInfo(uid, password); } } if (userinfo != null) { HttpCookie admincookie = Request.Cookies["cmsntadmin"]; admininfo = null; if (admincookie != null && admincookie.Values["adminid"] != null && admincookie.Values["password"] != null) { int adminid = Convert.ToInt32(admincookie.Values["adminid"]); string password = admincookie.Values["password"].ToString().Trim(); if (adminid > 0 && password != string.Empty) { //admininfo todo admininfo = Admins.GetAdminInfo(adminid, password); if (admininfo != null && admininfo.Uid == userinfo.Uid) { admincookie.Expires = DateTime.Now.AddMinutes(20d); Response.AppendCookie(admincookie); adminpath = admincookie.Values["path"].ToString().Trim(); return(true); } } } } adminpath = ""; return(false); }
protected virtual bool IsAdminLogined() { //UserInfo userinfo = GetUserInfo(); if (userid > 0) { YCookies admincookie = new YCookies("cmsntadmin"); int adminid = admincookie.GetCookieIntValue("adminid", 0); string password = admincookie.GetCookieStringValue("password").Trim(); admininfo = null; if (adminid > 0 && password != string.Empty) { admininfo = Admins.GetAdminInfo(adminid, password); if (admininfo != null && admininfo.Uid == userid) { adminpath = admincookie.GetCookieStringValue("path").Trim(); return(true); } } } //登录失败 adminpath = ""; return(false); }