コード例 #1
0
        public async Task <IActionResult> LoginWith2fa()
        {
            if (User.Identity.IsAuthenticated)
            {
                return(AdminDashboardActionResult);
            }
            var user = await this.authenticationService.GetTwoFactorAuthenticationUserAsync(HttpContext);

            if (user == null || !(await this.authenticationService.UserHasAdministrationAccessRightsAsync(user)))
            {
                return(NotFound());
            }

            AdminLoginWith2faViewModel model = new AdminLoginWith2faViewModel();

            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> LoginWith2fa(AdminLoginWith2faViewModel model)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                return(this.AdminDashboardActionResult);
            }

            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var user = await this.authenticationService.GetTwoFactorAuthenticationUserAsync <User>(this.HttpContext);

            if (user == null || !(await this.authenticationService.UserHasAdministrationAccessRightsAsync(user)))
            {
                return(this.NotFound());
            }

            var authenticatorCode = model.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);

            var result = await this.authenticationService.SignInWith2faAsync(user, authenticatorCode, false, this.HttpContext, CookieAuthenticationDefaults.AuthenticationScheme, this.AuthenticationProperties);

            if (result.Succeeded)
            {
                return(this.AdminDashboardActionResult);
            }
            else if (result.IsLockedOut)
            {
                return(this.RedirectToAction(nameof(this.Lockout)));
            }
            else
            {
                this.ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
                return(this.View(model));
            }
        }