예제 #1
0
        public ActionResult Login(MALL.ViewModel.SNS.LogOnModel model, string returnUrl)
        {
            ViewBag.Title = "登录";
            bool IsCloseLogin = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("System_Close_Login");

            if (IsCloseLogin)
            {
                return(RedirectToAction("TurnOff", "Error"));
            }
            if (ModelState.IsValid)
            {
                AccountsPrincipal userPrincipal = AccountsPrincipal.ValidateLogin(model.Email, model.Password);
                if (userPrincipal == null)
                {
                    ModelState.AddModelError("Message", "用户名或密码不正确, 请重新输入!");
                    return(View(model));
                }

                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (!currentUser.Activity)
                {
                    ModelState.AddModelError("Message", "对不起,该帐号已被冻结,请联系管理员!");
                    return(View(model));
                }
                HttpContext.User = userPrincipal;
                FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
                Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                //登录成功加积分
                YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                int pointers  = pointBll.AddPoints(1, currentUser.UserID, "登录操作");
                int rankScore = BLL.Members.RankDetail.AddScore(1, currentUser.UserID, "登录操作");

                #region 默认加小组  加失败之后显示加入小组按钮
                //加入小组
                YSWL.MALL.Model.SNS.GroupUsers groupModel = new Model.SNS.GroupUsers();
                if (!bll.Exists(GroupId, currentUser.UserID))
                {
                    groupModel.GroupID  = GroupId;
                    groupModel.JoinTime = DateTime.Now;
                    groupModel.NickName = currentUser.NickName;
                    groupModel.UserID   = currentUser.UserID;
                    groupModel.Status   = 1;
                    if (!bll.AddEx(groupModel))
                    {
                        ViewBag.joined = "error";
                    }
                }
                #endregion


                //加载Shop模块的购物车
                if (CurrentThemeName == "TaoLe")
                {
                    BLL.Shop.Products.ShoppingCartHelper.LoadShoppingCart(currentUser.UserID);
                }

                if (Session["ReturnUrl"] != null && !String.IsNullOrWhiteSpace(Session["ReturnUrl"].ToString()))
                {
                    returnUrl = Session["ReturnUrl"].ToString();
                    Session.Remove("ReturnUrl");
                    return(Redirect(returnUrl));
                }
                if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                    !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    TempData["pointer"]   = pointers;
                    TempData["rankScore"] = rankScore;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }
예제 #2
0
        /// <summary>
        /// 重写父类的登录跳转, 指向SNS登录
        /// </summary>
        public override ActionResult RedirectToLogin(ActionExecutingContext filterContext)
        {
            string rawurl      = Request.RawUrl;
            bool   IsAutoLogin = Common.Globals.SafeBool(YSWL.WeChat.BLL.Core.Config.GetValueByCache("WeChat_AutoLogin", -1, "AA"), false);

            #region  自动登陆
            bool IsNeedBind = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("SyStem_WeChat_UserBind");

            if (Session[YSWL.Common.Globals.SESSIONKEY_USER] != null && CurrentUser != null && CurrentUser.UserType != "AA")
            {
                BLL.Shop.Products.ShoppingCartHelper.LoadShoppingCart(currentUser.UserID);
                return(String.IsNullOrWhiteSpace(rawurl) ? Redirect(ViewBag.BasePath) : Redirect(rawurl));
            }
            YSWL.WeChat.BLL.Core.User wUserBll = new WeChat.BLL.Core.User();
            if (String.IsNullOrWhiteSpace(OpenId) || String.IsNullOrWhiteSpace(UserOpen))
            {
                return(Redirect(ViewBag.BasePath + "Account/Login?returnUrl=" + Server.UrlEncode(rawurl)));
            }
            YSWL.WeChat.Model.Core.User wUserModel = wUserBll.GetUser(OpenId, UserOpen);
            if (IsNeedBind)
            {
                if (wUserModel.UserId <= 0)
                {
                    return(Redirect(ViewBag.BasePath + "Account/Login?returnUrl=" + Server.UrlEncode(rawurl)));
                }
                AccountsPrincipal userPrincipal = new AccountsPrincipal(wUserModel.UserId);
                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (!currentUser.Activity)
                {
                    return(Redirect(ViewBag.BasePath + "Account/Login?returnUrl=" + Server.UrlEncode(rawurl)));
                }
                HttpContext.User = userPrincipal;

                #region 自动加入小组
                int groupId = BLL.SysManage.ConfigSystem.GetIntValueByCache("V_SNS_GroupId");
                YSWL.MALL.Model.SNS.GroupUsers groupModel = new Model.SNS.GroupUsers();
                YSWL.MALL.BLL.SNS.GroupUsers   bll        = new YSWL.MALL.BLL.SNS.GroupUsers();
                if (!bll.Exists(groupId, currentUser.UserID))
                {
                    groupModel.GroupID  = groupId;
                    groupModel.JoinTime = DateTime.Now;
                    groupModel.NickName = currentUser.NickName;
                    groupModel.UserID   = currentUser.UserID;
                    groupModel.Status   = 1;
                    if (!bll.AddEx(groupModel))
                    {
                        ViewBag.joined = "error";
                    }
                }
                #endregion

                Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                FormsAuthentication.SetAuthCookie(currentUser.UserName, true);
                return(String.IsNullOrWhiteSpace(rawurl) ?
                       Redirect(ViewBag.BasePath + "Home") : Redirect(rawurl));
            }
            if (IsAutoLogin)
            {
                string AutoLoginUrl = "/COM/Account/RegBind?returnUrl=" + Server.UrlEncode(rawurl);
                if (wUserModel.UserId <= 0)
                {
                    return(Redirect(AutoLoginUrl));
                }
                AccountsPrincipal userPrincipal = new AccountsPrincipal(wUserModel.UserId);
                if (userPrincipal == null)
                {
                    return(Redirect(AutoLoginUrl));
                }
                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (!currentUser.Activity)
                {
                    return(Redirect(AutoLoginUrl));
                }
                HttpContext.User = userPrincipal;
                Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                FormsAuthentication.SetAuthCookie(currentUser.UserName, true);
                return(String.IsNullOrWhiteSpace(rawurl) ? Redirect(ViewBag.BasePath) : Redirect(rawurl));
            }

            #endregion

            return(Redirect(ViewBag.BasePath + "Account/Login?returnUrl=" + Server.UrlEncode(rawurl)));
        }