Пример #1
0
        public ActionResult Login(LoginViewModel loginView)
        {
            if (ModelState.IsValid)
            {
                int userId = _authProvider.Authenticate(loginView.Email, loginView.Password);
                if (userId > 0)
                {
                    string authId = Guid.NewGuid().ToString();
                    Session["AuthID"] = authId;
                    Session["UserId"] = userId;
                    var cookie = new HttpCookie("AuthID") {Value = authId};
                    Response.Cookies.Add(cookie);
                    return RedirectToAction("MainWindow", "UserMain", new {Id = userId});
                }

                ModelState.AddModelError("", "Невірний email або пароль");
                return View();
            }

            ModelState.AddModelError("", "Необхідно заповнити всі поля");
            return View();
        }
Пример #2
0
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(model);
            }
        }
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // 这不会计入到为执行帐户锁定而统计的登录失败次数中
            // 若要在多次输入错误密码的情况下触发帐户锁定,请更改为 shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "无效的登录尝试。");
                    return View(model);
            }
        }
Пример #4
0
 private ActionResult LoginView(LoginViewModel model)
 {
     ViewData["LoginProviders"] = AuthenticationManager.GetExternalAuthenticationTypes();
     return View(ViewNames.Login, model);
 }
Пример #5
0
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return LoginView(model);
            }

            // これは、アカウント ロックアウトの基準となるログイン失敗回数を数えません。
            // パスワード入力失敗回数に基づいてアカウントがロックアウトされるように設定するには、shouldLockout: true に変更してください。
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    return RedirectToLocal(returnUrl);
                case SignInStatus.LockedOut:
                    return LockoutView();
                case SignInStatus.RequiresVerification:
                    return RedirectToSendCode(model, returnUrl);
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", Properties.Resources.Account_Login_InvalidLoginAttempt); //  "無効なログイン試行です。"
                    return LoginView(model);
            }
        }
Пример #6
0
 private ActionResult RedirectToSendCode(LoginViewModel model, string returnUrl)
 {
     return RedirectToAction(ActionNames.SendCode, new { ReturnUrl = returnUrl, model.RememberMe });
 }