public async Task <IActionResult> SignIn(Signin_DashboardModel collection, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var admin = await _adminContainer.SignInAsync(collection.Username, collection.Password);

                if (admin != null)
                {
                    if (admin.Status != 1)
                    {
                        Log.Information($"The lockout '{admin.FullName} (Id: {admin.Id})' tried to sign in.");
                        return(View("Lockout"));
                    }
                    //TODO: RequiresTwoFactor
                    Log.Information($"'{admin.FullName} (Id: {admin.Id})' signed in.");
                    var accountPrincipal = _mapper.Map <AccountPrincipal>(admin);
                    accountPrincipal.IP = IP;
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, accountPrincipal, new AuthenticationProperties {
                        IsPersistent = collection.RememberMe
                    });

                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, _stringLocalizer[SharedResource.InvalidSigninAttempt]);
                    return(View(collection));
                }
            }
            // There is obviously something wrong
            return(View(collection));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostSigninAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var result = await _adminContainer.SignInAsync(Username, Password);

            if (result == null)
            {
                ModelState.AddModelError(string.Empty, _stringLocalizer["SigninFailed"]);
                return(Page());
            }
            return(RedirectToPage("home", "get"));
        }