protected void btnLogin_Click(object sender, ImageClickEventArgs e) { //if (!VerifyCodeHelper.IsValid(Context, vc.ID)) //{ // Response.Write("<script>alert('验证码不正确!');</script>"); // return; //} AdminCookie cookie = new AdminCookie(); cookie.Username = Request.Form[tbUsername.ID]; cookie.Password = Request.Form[tbPassword.ID]; OperatorStaus status = UserOperation.UserLogin(cookie); switch (status) { case OperatorStaus.SUCCESS: string url = RuleAuthorizationManager.GetPreviousUrl(Context); RuleAuthorizationManager.Authorize(Context, cookie); if (StringHelper.IsEmpty(url)) { Response.Redirect("/Admin/Main"); } else { Response.Redirect(url); } break; case OperatorStaus.OPERATOR_USERNAME_INCORROECT: Response.Write("<script>alert('用户名错误!');</script>"); break; case OperatorStaus.OPERATOR_PASSWORD_INCORROECT: Response.Write("<script>alert('密码错误!');</script>"); break; } }
public static void BindRuleModules(AdminCookie cookie, List<ModuleAuthorization> mas) { cookie.RuleModules = new Dictionary<int, IRuleModule>(); if (mas == null) return; foreach (ModuleAuthorization ma in mas) { cookie.RuleModules.Add(ma.ModuleId, ma); } }
public static AdminCookie GetAdmin() { HttpCookie cookie = HttpContext.Current.Request.Cookies[COOKIE_ADMIN_PSW]; string psw = cookie == null ? string.Empty : HttpUtility.UrlDecode(cookie.Value); cookie = HttpContext.Current.Request.Cookies[COOKIE_ADMIN_NAME]; string username = cookie == null ? string.Empty : HttpUtility.UrlDecode(cookie.Value); cookie = HttpContext.Current.Request.Cookies[COOKIE_ADMIN_ID]; string sId = cookie == null ? string.Empty : cookie.Value; int id = 0; AdminCookie ac = null; if (sId != null && int.TryParse(sId, out id)) { ac = new AdminCookie(); ac.Id = id; ac.Username = username; ac.Password = psw; } return ac; }