Ejemplo n.º 1
0
        public ActionResult Logout()
        {
            string url = "";

            this.Session.Clear();
            var cookie = Response.Cookies["rememberMeLogin"];

            if (cookie != null)
            {
                cookie.Expires = DateTime.Now.AddDays(-100);
            }
            var acookie = Response.Cookies["rememberMeName"];

            if (cookie != null)
            {
                acookie.Expires = DateTime.Now.AddDays(-100);
            }
            if (UserContext.Current.Groupid == (int)Common.CommonEnum.GroupOfCustomer.OpenShop)
            {
                url = "/Merchant/Company_Login";
            }
            else
            {
                url = "/Login";
            }
            YG.SC.OpenShop.Authentication.FormAuthenticationService fom = new FormAuthenticationService();
            fom.SignOut();
            return(Redirect(url));
        }
Ejemplo n.º 2
0
        private void WriteUserSession(Customer user, string rememberMe)
        {
            Session[CommonContorllers.UserIdCacheName]   = user.Id;
            Session[CommonContorllers.UserNameCacheName] = user.LoginName;

            //if (!rememberMe.Equals("true", StringComparison.OrdinalIgnoreCase))
            //{
            //    var cookie = Response.Cookies["rememberMeName"];
            //    if (cookie != null)
            //        cookie.Expires = DateTime.Now.AddDays(-100);
            //    var httpCookie = Response.Cookies["rememberMePassword"];
            //    if (httpCookie != null)
            //        httpCookie.Expires = DateTime.Now.AddDays(-100);
            //}
            //else
            //{
            var _authenticationService = new FormAuthenticationService();

            _authenticationService.SignIn(user.LoginName, true);

            var aCookie = new HttpCookie("rememberMeName")
            {
                Value = user.LoginName, Expires = DateTime.Now.AddDays(10)
            };
            var cCookie = new HttpCookie("rememberMeLogin")
            {
                Value = rememberMe, Expires = DateTime.Now.AddDays(10)
            };

            Response.Cookies.Add(aCookie);
            Response.Cookies.Add(cCookie);
            //}
        }
Ejemplo n.º 3
0
        public ActionResult Login(string LoginName, string Password, string rememberMe = "checked", string returnUrl = "")
        {
            this.Session.Clear();
            var cookie = Response.Cookies["rememberMeLogin"];

            if (cookie != null)
            {
                cookie.Expires = DateTime.Now.AddDays(-100);
            }
            var acookie = Response.Cookies["rememberMeName"];

            if (cookie != null)
            {
                acookie.Expires = DateTime.Now.AddDays(-100);
            }
            YG.SC.OpenShop.Authentication.FormAuthenticationService fom = new FormAuthenticationService();
            fom.SignOut();
            //获取账户
            string message = "IsSuccss";
            var    entity  = this._iCustomerService.GetEntityByNameAndPassword(LoginName, Password);

            if (entity == null ||
                !entity.GroupId.HasValue ||
                (CommonEnum.GroupOfCustomer)entity.GroupId != CommonEnum.GroupOfCustomer.Member && (CommonEnum.GroupOfCustomer)entity.GroupId != CommonEnum.GroupOfCustomer.OpenShop
                )                //前台只有会员和商家可以登录。
            {
                entity = null;
            }
            if (entity == null)
            {
                message     = "用户名或密码错误";
                ViewBag.msg = message;
                return(View("index"));
                // if (!entity.Password.Equals(Password)) return "密码错误";
                //if (entity.UserCd != UserCdSenior) return Json(new ResultModel(false, "权限错误"));
            }

            if (entity.GroupId == (int)YG.SC.Common.CommonEnum.GroupOfCustomer.Member)
            {
                WriteUserSession(entity, rememberMe);
                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(HttpUtility.UrlDecode(returnUrl)));
                }
                return(Redirect("~/Customer/Memberindex/" + entity.Companyid));
            }
            else
            {
                message     = "用户名或密码错误";
                ViewBag.msg = message;
                return(View());
            }
        }
Ejemplo n.º 4
0
        private void WriteUserSession(Customer user, string rememberMe)
        {
            Session[CommonContorllers.UserIdCacheName]   = user.Id;
            Session[CommonContorllers.UserNameCacheName] = user.LoginName;
            var _authenticationService = new FormAuthenticationService();

            _authenticationService.SignIn(user.LoginName, true);
            var aCookie = new HttpCookie("rememberMeName")
            {
                Value = user.LoginName, Expires = DateTime.Now.AddDays(10)
            };
            var cCookie = new HttpCookie("rememberMeLogin")
            {
                Value = rememberMe, Expires = DateTime.Now.AddDays(10)
            };

            Response.Cookies.Add(aCookie);
            Response.Cookies.Add(cCookie);
        }
Ejemplo n.º 5
0
        public ContentResult LoginAjax(string LoginName, string Password, string rememberMe = "checked", string returnUrl = "")
        {
            this.Session.Clear();
            var cookie = Response.Cookies["rememberMeLogin"];

            if (cookie != null)
            {
                cookie.Expires = DateTime.Now.AddDays(-100);
            }
            var acookie = Response.Cookies["rememberMeName"];

            if (cookie != null)
            {
                acookie.Expires = DateTime.Now.AddDays(-100);
            }
            YG.SC.OpenShop.Authentication.FormAuthenticationService fom = new FormAuthenticationService();
            fom.SignOut();
            //获取账户
            string message = "IsSuccss";
            var    entity  = this._iCustomerService.GetEntityByNameAndPassword(LoginName, Password);

            if (entity == null ||
                !entity.GroupId.HasValue ||
                (CommonEnum.GroupOfCustomer)entity.GroupId != CommonEnum.GroupOfCustomer.Member
                )                //只有会员可以登录。
            {
                entity = null;
            }
            if (entity == null)
            {
                message     = "用户名或密码错误";
                ViewBag.msg = message;
                return(Content("0"));               //登录失败。
            }
            WriteUserSession(entity, rememberMe);
            return(Content("1"));           //登录成功。
        }