コード例 #1
0
ファイル: SigninController.cs プロジェクト: hoya0/sw
        public ActionResult Signin(FormCollection form)
        {
            var returnResult = new Swoopo.Model.JsonResult();
            UserEntity userResult;
            try
            {
                var bll = new UserBll();
                var user = new UserEntity
                {
                    UserName = form.Get("UserName"),
                    UserPwd = form.Get("UserPwd"),
                    Email = "*****@*****.**"
                };
                //由于登录时,不需要email,所有用“[email protected]”替代,否则验证无法通过

                Validator<UserEntity> userValid = ValidationFactory.CreateValidator<UserEntity>();
                ValidationResults r = userValid.Validate(user);
                if (!r.IsValid)
                {
                    var list = r.Select(result => result.Message).ToList();

                    returnResult.error = list;
                    return Json(returnResult);
                }
                user.UserPwd = We7Utils.MD5(user.UserPwd);
                userResult = bll.Signin(user);
            }
            catch (BllException ex)
            {
                #if DEBUG
                returnResult.error = ex.InnerException.Message;
                #else
                returnResult.error = ex.Message;
                #endif
                return Json(returnResult);
            }
            catch (DalException dalException)
            {
                #if DEBUG
                returnResult.error = dalException.InnerException.Message;
                #else
                returnResult.error = dalException.Message;
                #endif
                return Json(returnResult);
            }

            if (userResult == null)
            {
                //ModelState.AddModelError("", "用户名或密码不正确!");
                //return View("Signin");
                returnResult.error = "用户名或密码不正确!";
                return Json(returnResult);
            }
            returnResult.value = true;
            Session["UserEntity"] = userResult;

            return Json(returnResult);
        }
コード例 #2
0
ファイル: UserBLL.cs プロジェクト: hoya0/sw
        public UserEntity Signin(UserEntity user)
        {
            Dictionary<string, string> condition = new Dictionary<string, string>();
            condition.Add("UserName", user.UserName);
            condition.Add("UserPwd", user.UserPwd);
            UserEntity userResult = new DAL.UserDAL().Signin(user, condition);

            if (userResult != null && userResult.UserState == 0)
            {
                throw new BllException("用户为停用状态,请联系管理员!");
            }

            return userResult;
        }