public async Task <Result <AddTwoFactorAuthenticatorViewModel> > GetAuthenticatorViewModel()
        {
            Result <AppUserEntity> getAppUserResult = await GetAppUser();

            if (getAppUserResult.Failure)
            {
                return(Result.Fail <AddTwoFactorAuthenticatorViewModel>(getAppUserResult.Errors));
            }

            AppUserEntity appUser = getAppUserResult.Value;

            Result <(string sharedKey, string authenticatorUri)> result = await _twoFactorAuthService.Generate2faCode(appUser.Id);

            if (result.Failure)
            {
                return(Result.Fail <AddTwoFactorAuthenticatorViewModel>(result.Errors));
            }

            (string sharedKey, string authenticatorUri) = result.Value;

            AddTwoFactorAuthenticatorViewModel model = new AddTwoFactorAuthenticatorViewModel(
                sharedKey: sharedKey,
                authenticationUri: authenticatorUri);

            return(Result.Ok(model));
        }
Exemple #2
0
        public async Task <Result <AddTwoFactorAuthenticatorViewModel> > GetAddTwoFactorAuthenticatorViewModel(string userId, string sessionCode, string ip)
        {
            Result <(string sharedKey, string authenticatorUri)> result = await _twoFactorAuthService.Generate2faCode(userId, sessionCode, ip);

            if (result.Failure)
            {
                return(Result.Fail <AddTwoFactorAuthenticatorViewModel>(result.Errors));
            }

            (string sharedKey, string authenticatorUri) = result.Value;

            AddTwoFactorAuthenticatorViewModel model = new AddTwoFactorAuthenticatorViewModel(
                sharedKey: sharedKey,
                authenticationUri: authenticatorUri);

            return(Result.Ok(model));
        }
        public async Task <IActionResult> AddTwoFactorAuthenticator()
        {
            Result <AddTwoFactorAuthenticatorViewModel> result = await _twoFactorAuthorizationDataService.GetAuthenticatorViewModel();

            if (result.Failure)
            {
                SaveTempData(INDEX_STATUS_ALERT_TEMP_DATA_KEY, StatusAlertViewExtension.Get(result));
                return(RedirectToAction(nameof(Index)));
            }

            AddTwoFactorAuthenticatorViewModel addTwoFactorAuthenticator = result.Value;

            StatusAlertViewModel statusAlert = GetTempData <StatusAlertViewModel>(AUTHENTICATOR_STATUS_ALERT_TEMP_DATA_KEY);

            if (statusAlert != null)
            {
                ModelState.AddErrors(statusAlert.ValidationErrors);
                addTwoFactorAuthenticator.StatusAlert = statusAlert;
            }

            return(View(addTwoFactorAuthenticator));
        }