Esempio n. 1
0
        public ActionResult Index(LoginViewModel user)
        {
            string captcha = user.Captcha;

            if (!ModelState.IsValid)
            {
                return(JavaScript("layer.msg('必填项未填写或数据格式不正确!');"));
            }
            if (null != Session["Captcha"] && captcha.ToLower() != Session["Captcha"].ToString().ToLower())
            {
                return(JavaScript(" layer.msg('验证码不正确');changeCaptcha();"));
            }
            var dbUser = userBLL.GetList(string.Format(" StopFlag=0 AND UserName='******' AND UserPwd='{1}' ",
                                                       user.UserCode, user.Password)).FirstOrDefault();

            if (dbUser == null)
            {
                return(JavaScript("layer.msg('用户名或密码错误!');changeCaptcha();"));
            }

            NBCZUser.WriteUser(user.UserCode);
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.UserCode, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), true, FormsAuthentication.FormsCookiePath);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));

            cookie.Domain = FormsAuthentication.CookieDomain;
            cookie.Path   = ticket.CookiePath;
            Response.Cookies.Add(cookie);
            return(JavaScript(string.Format("window.location.href='../Home/Index'")));
        }
Esempio n. 2
0
        /// <summary>
        /// 检查用户名是否重复
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        private bool IsUserNameRepeat(string userName)
        {
            var list = userBLL.GetList(string.Format("UserName='******'", userName), limits: 1);

            return(list != null && list.Count >= 1);
        }