public ActionResult LogOff() { Session[SessionManager.Instance.SessionKey] = null; SessionManager.Logout(); CookieHelp.SetCookie(SessionManager.Instance.UserInfoTicketKey, "", DateTime.Now.AddSeconds(5)); return(RedirectToAction("Index", "Home")); }
/// <summary> /// Action执行前 /// </summary> /// <param name="filterContext">上下文</param> public override void OnActionExecuting(ActionExecutingContext filterContext) { try { // var isajax = HttpContext.Current.Request.Headers["x-requested-with"]; object[] actionFilter = filterContext.ActionDescriptor.GetCustomAttributes(typeof(NoCompress), false); object[] controllerFilter = filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(NoCompress), false); if (controllerFilter.Length == 1 || actionFilter.Length == 1) { return; } bool flag = AES.UrlEncrypt(CookieHelp.GetCookieValByKey("Userid") + CookieHelp.GetCookieValByKey("LoginName")) == AES.UrlEncrypt(CookieHelp.GetCookieValByKey("long")); if (string.IsNullOrEmpty(CookieHelp.GetCookieValByKey("Userid")) || !flag) { HttpContext.Current.Response.Clear(); filterContext.Result = new RedirectResult(AppConfig.LoginUrl); HttpContext.Current.Response.Write("<script>parent.parent.window.location='" + AppConfig.LoginUrl + "';parent.window.location='" + AppConfig.LoginUrl + "'</script>"); HttpContext.Current.Response.End(); filterContext.Result = new EmptyResult(); } base.OnActionExecuting(filterContext); } catch (Exception exception) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Write(exception.Message); HttpContext.Current.Response.End(); filterContext.Result = new EmptyResult(); } }
/// <summary> /// 修改密码 /// </summary> /// <param name="Pwd"></param> /// <returns></returns> public ActionResult UpdatePwd(string Pwd) { user u = new user(); u.Id = Convert.ToInt64(CookieHelp.GetCookieValByKey("UserId")); u.Pwd = Pwd; fileds = new[] { "Pwd" }; return(base.Update(u)); }
public static bool isHasQuanXian(string action) { string UserId = CookieHelp.GetCookieValByKey("UserId"); Func <List <string> > per = () => new List <string>(); List <string> btnquanxian = CacheHelper.GetCache(UserId, per); if (btnquanxian.Contains(action)) { return(true); } else { return(false); } }
public ActionResult Login(string LoginName, string Pwd) { LoginLogDal logDal = new LoginLogDal(); user u = GetOne(q => q.LoginName == LoginName.Trim()); if (u.Pwd == Pwd) { CookieHelp.SetCookies("UserId", u.Id.ToString(), DateTime.Now.AddDays(1)); CookieHelp.SetCookies("LoginName", u.LoginName, DateTime.Now.AddDays(1)); CookieHelp.SetCookies("long", u.Id.ToString() + u.LoginName, DateTime.Now.AddDays(1)); logDal.Add(u); return(Success()); } else { return(Error(new Exception("登陆失败"))); } }
/// <summary> /// 检查QQ是否需要验证码,并获取参数 /// </summary> /// <returns></returns> public bool CheckQQNum() { string url = "https://ssl.ptlogin2.qq.com/check?uin=" + this.QQNum + "&appid=501004106&js_ver=10095&js_type=0&login_sig=a9NQ-9*PnzKFxzP7jcE7voRx5Z9x6Khffy44FKhIkaD-n8fShtaK1r1GZRjgsxzA&u1=http%3A%2F%2Fw.qq.com%2Fproxy.html&r=0.6158497643191367"; string html = this.HP.GetHtml(url, null, Encoding.UTF8, true); string pattern = @"(?<=')[^,]*?(?=')"; List <string> para = MatchHelp.GetValues(html, pattern); if (para[0] == "0") // 如果无需验证码 { this.CodeString = para[1]; this.QQUin = para[2]; this.VerifySession = para[3]; return(true); } else // 需要验证码 { string imageUrl = "https://ssl.captcha.qq.com/getimage?aid=501004106&r=0.8478438374586403&uin=" + this.QQNum; string imageReferer = "https://ui.ptlogin2.qq.com/cgi-bin/login?daid=164&target=self&style=16&mibao_css=m_webqq&appid=501004106&enable_qlogin=0&no_verifyimg=1&s_url=http%3A%2F%2Fw.qq.com%2Fproxy.html&f_url=loginerroralert&strong_login=1&login_state=10&t=20131024001"; // 获取验证码 System.Drawing.Image image = this.HP.getImage(imageUrl, imageReferer, true); //获取verifysession 和 uin this.VerifySession = CookieHelp.GetCookieValue(this.HP.CookieCollection, "verifysession"); if (string.IsNullOrEmpty(VerifySession)) { onError(new ErrorEventArgs() { Error = "找不到verifysession..." }); return(false); } this.QQUin = para[2]; //通知显示验证码 onNeedCode(new NeedCodeEventArgs() { Image = image }); return(false); } }
/// <summary> /// 填充用户登录信息 /// </summary> /// <param name="model">登录模型</param> /// <param name="info">登录用户信息</param> /// <returns>true 成功 false 失败</returns> public bool FillLoginInfo(UserLoginInfo info, LoginViewModel model = null) { try { //写入Session信息 Session[SessionManager.Instance.SessionKey] = info; if (model != null) { //写入用户信息票据,有效期为浏览器进程 AccountTicket usertick = new AccountTicket(); usertick.Password = model.Password; usertick.SessionId = Session.SessionID; usertick.UserAccount = model.LoginName; string strticket = usertick.UserAccount; CookieHelp.SetCookie(SessionManager.Instance.UserInfoTicketKey, strticket, DateTime.Now.AddDays(1)); } //if (model.IsAutoLogin) //{ // //下次自动登录,写入自动登录票据 // QM_LoginTicket loginticket = new QM_LoginTicket(); // loginticket.CreateTime = DateTime.Now; // loginticket.UserName = model.UserAccount; // loginticket.UserPassword = model.UserPassword; // string strlogin = SerializableHelp.SerializableAndEncrypt<QM_LoginTicket>(loginticket); // CookieHelp.SetCookie(SessionManager.Instance.UserAutoLoginTicketKey, strlogin, DateTime.MaxValue); //} } catch (Exception ex) { //LogHelper.WriteLog("登录信息填充失败", ex); return(false); } return(true); }