Beispiel #1
0
        public async Task <IActionResult> Login([FromForm] LoginAccountAccountView loginAccountAccountView)
        {
            try
            {
                await _accountService.SignIn(loginAccountAccountView);

                if (string.IsNullOrWhiteSpace(loginAccountAccountView.ReturnUrl))
                {
                    return(Redirect("~/"));
                }

                return(Redirect($"~{loginAccountAccountView.ReturnUrl}"));
            }
            catch (AccountException ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View());
            }
        }
Beispiel #2
0
        public async Task SignIn(LoginAccountAccountView loginAccountAccountView)
        {
            var user = await _userManager.FindByEmailAsync(loginAccountAccountView.Email);

            if (user is null)
            {
                throw new AccountException("Couldn't sign in. UserName or password is incorrect.");
            }

            if (!user.EmailConfirmed)
            {
                throw new AccountException("Couldn't sign in. Please, confirm your email address.");
            }

            SignInResult result = await _signInManager.PasswordSignInAsync(user.UserName, loginAccountAccountView.Password, false, false);

            if (!result.Succeeded)
            {
                throw new AccountException("Couldn't sign in. UserName or password is incorrect.");
            }
        }