Ejemplo n.º 1
0
        public ActionResult login(UserLogOnModel model)
        {
            if (!_validateCodeService.CheckCode(model.ValidCode))
            {
                _validateCodeService.ClearSession();
                return(Json(new { result = false, message = "验证码不正确" }, JsonRequestBehavior.AllowGet));
            }

            var userInfo = _accountInfoTask.GetAccount(model.Account);

            if (userInfo == null)
            {
                return(Json(new { result = false, message = "用户不存在" }, JsonRequestBehavior.AllowGet));
            }

            if (userInfo.Password != CryptTools.HashPassword(model.Password))
            {
                return(Json(new { result = false, message = "用户名或密码不正确" }, JsonRequestBehavior.AllowGet));
            }

            // 添加登录日志

            _accountLoginLogTask.Add(new AccountLoginLog
            {
                Account    = userInfo.Account,
                CreateDate = DateTime.Now,
                IP         = DNTRequest.GetIP(),
            });
            // 更新购物车


            FormsAuthServiceCookie.SignIn(model.Account, false);
            return(Json(new { result = true, message = string.Empty }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult reg(RegisterModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (!_validateCodeService.CheckCode(model.ValidCode))
                {
                    return(AlertMsg("验证码不正确", Request.UrlReferrer.PathAndQuery));
                }


                if (_accountInfoTask.ExistsEmail(model.Email))
                {
                    return(AlertMsg("电子邮箱已存在", Request.UrlReferrer.PathAndQuery));
                }

                var ipAddress = DNTRequest.GetIP();
                var userInfo  = _accountInfoTask.Register(model.Email, model.Password, model.Email, ipAddress, "", DNTRequest.GetIP());
                FormsAuthServiceCookie.SignIn(model.Email, false);

                return(string.IsNullOrEmpty(returnUrl)
                          ? Redirect(Url.Action("Index", "Home"))
                          : Redirect(returnUrl));
            }
            return(AlertMsg("注册出错,请联系管理员", Request.UrlReferrer.ToString()));
        }
Ejemplo n.º 3
0
 protected override void OnAuthorization(AuthorizationContext filterContext)
 {
     if (!FormsAuthServiceCookie.IsSignedIn())
     {
         filterContext.HttpContext.Response.Write("<script>window.top.location.href='/personal/login';</script>");
         filterContext.HttpContext.Response.End();
         return;
     }
 }
Ejemplo n.º 4
0
 public ActionResult LogOff()
 {
     FormsAuthServiceCookie.SignOut();
     return(RedirectToAction("Index", "Home"));
 }