Ejemplo n.º 1
0
        public ActionResult MLogon(string returnUrl = "")
        {
            var model = new MLogonModel();

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult MLogon(MLogonModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (model.Mobile != null)
                {
                    model.Mobile = model.Mobile.Trim();
                }
                UserLoginResults loginResult = _accountService.ValidateUserByMobile(model.Mobile, model.Password);
                if (loginResult == UserLoginResults.UserNotExist)
                {
                    loginResult = _accountService.ValidateUser(model.Mobile, model.Password);
                }
                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    User user = _service.GetUserByMobile(model.Mobile) ?? _service.GetUserByUsername(model.Mobile);
                    //sign in new customer
                    AuthenticationService.SignIn(user, true);

                    if (String.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    return(Redirect(returnUrl));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", "用户不存在");
                    break;

                case UserLoginResults.IsIllegal:
                    ModelState.AddModelError("", "您的账户已被禁用");
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", "用户已删除");
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", "用户没有激活");
                    break;

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", "用户未注册");
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", "密码错误");
                    break;
                }
            }
            return(View(model));
        }