Exemple #1
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("", Act.LoginFailMessage);
                return(View(model));
            }

            //if user's email is not confirmed, resend link and return view with error
            if (!user.EmailConfirmed)
            {
                await _userRegistrationService.SendEmailConfirmationLink(Request, model.Email);

                ModelState.AddModelError("", Act.UnconfirmedEmailMessage);
                return(View(model));
            }

            //var loginResult = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false);
            var loginResult = await _signInManager.PasswordSignInAsync(user, model.Password, false, false);

            if (loginResult.Succeeded)
            {
                if (string.IsNullOrEmpty(returnUrl) || returnUrl.Contains("confirmemail"))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                return(RedirectToLocal(returnUrl));
            }

            if (loginResult.IsLockedOut)
            {
                return(View("Lockout"));
            }
            if (loginResult.Succeeded == false)
            {
                ModelState.AddModelError("", Act.LoginFailMessage);
            }
            return(View(model));
        }