Esempio n. 1
0
        public async Task <IActionResult> Login(VeganLoginVM viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            // Check if credentials is valid (and set auth cookie)
            var result = await service.TryLoginAsync(viewModel);

            if (!result.Succeeded)
            {
                // Show error
                ModelState.AddModelError(nameof(VeganLoginVM.Username), "Login failed");
                return(View(viewModel));
            }

            // Redirect user
            if (string.IsNullOrWhiteSpace(viewModel.ReturnUrl))
            {
                return(RedirectToAction(nameof(Recipes)));
            }
            else
            {
                return(Redirect(viewModel.ReturnUrl));
            }
        }
Esempio n. 2
0
 public async Task <SignInResult> TryLoginAsync(VeganLoginVM viewModel)
 {
     // Try to sign user
     return(await signInManager.PasswordSignInAsync(
                viewModel.Username,
                viewModel.Password,
                isPersistent : false,
                lockoutOnFailure : false));
 }