Beispiel #1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var loginResult = _userService.ValidateUser(model.UserNameOrEmail, model.Password);
                switch (loginResult)
                {
                    case UserLoginResult.Successful:
                        {
                            var user = _userService.GetUserByUserNameOrEmail(model.UserNameOrEmail);

                            //sign in new user
                            _userService.SignIn(user, model.RememberMe);

                            //activity log
                            //_userActivityService.InsertActivity("PublicStore.Login", _localizationService.GetResource("ActivityLog.PublicStore.Login"), user);

                            if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                                return Redirect(returnUrl);
                            else
                                return RedirectToAction("Index");
                        }
                    case UserLoginResult.UserNotExist:
                        ModelState.AddModelError("", "该用户不存在");
                        break;
                    case UserLoginResult.Deleted:
                        ModelState.AddModelError("", "该用户已被删除");
                        break;
                    case UserLoginResult.NotActive:
                        ModelState.AddModelError("", "该用户没有被激活");
                        break;
                    case UserLoginResult.NotRegistered:
                        ModelState.AddModelError("", "该用户不存在");
                        break;
                    case UserLoginResult.WrongPassword:
                    default:
                        ModelState.AddModelError("", "密码错误");
                        break;
                }
            }
            return View(model);
        }
Beispiel #2
0
 public ActionResult Login()
 {
     var model = new LoginModel();
     return View(model);
 }