public async Task <IActionResult> ResetTwoFactorAuthenticatorPost() { TwoFactorAuthenticatorViewModel viewModel; Result result = await _twoFactorAuthService.Reset(GetUserId(), GetSessionCode(), GetIp()); if (result.Failure) { viewModel = new TwoFactorAuthenticatorViewModel(StatusAlertViewExtension.Get(result)); ModelState.AddErrors(result.Errors); return(View(viewModel)); } TwoFactorAuthenticatorViewModel twoFaViewModel = new TwoFactorAuthenticatorViewModel(StatusAlertViewExtension.Get("Two factor authentication reset.")); return(View("TwoFactorAuthenticator", twoFaViewModel)); }
public Result <TwoFactorAuthenticatorViewModel> GetTwoFactorAuthenticatorViewModel(string userId) { SelectSpecification <AppUserEntity, TwoFactorAuthenticatorViewModel> selectSpecification = new SelectSpecification <AppUserEntity, TwoFactorAuthenticatorViewModel>(); selectSpecification.AddFilter(x => x.Id == userId); selectSpecification.AddSelect(x => new TwoFactorAuthenticatorViewModel( x.TwoFactorEnabled)); TwoFactorAuthenticatorViewModel twoFactorAuthenticatorViewModel = _userRepository.Get(selectSpecification); if (twoFactorAuthenticatorViewModel == null) { _logger.LogWarning($"No user. UserId {userId}"); return(Result.Fail <TwoFactorAuthenticatorViewModel>("no_user", "No User")); } return(Result.Ok(twoFactorAuthenticatorViewModel)); }
public IActionResult Index() { Result <TwoFactorAuthenticatorViewModel> result = _twoFactorAuthorizationDataService.GetTwoFactorAuthenticatorViewModel(); if (result.Failure) { return(View(new TwoFactorAuthenticatorViewModel(StatusAlertViewExtension.Get(result)))); } TwoFactorAuthenticatorViewModel twoFactorAuthenticatorViewModel = result.Value; StatusAlertViewModel statusAlert = GetTempData <StatusAlertViewModel>(INDEX_STATUS_ALERT_TEMP_DATA_KEY); if (statusAlert != null) { ModelState.AddErrors(statusAlert.ValidationErrors); twoFactorAuthenticatorViewModel.StatusAlert = statusAlert; } return(View(twoFactorAuthenticatorViewModel)); }
public Result <TwoFactorAuthenticatorViewModel> GetTwoFactorAuthenticatorViewModel() { string userId = _httpContextAccessor.HttpContext.User.GetUserId(); SelectSpecification <AppUserEntity, TwoFactorAuthenticatorViewModel> selectSpecification = new SelectSpecification <AppUserEntity, TwoFactorAuthenticatorViewModel>(); selectSpecification.AddFilter(x => x.Id == userId); selectSpecification.AddSelect(x => new TwoFactorAuthenticatorViewModel( x.TwoFactorEnabled, x.TwoFactor.ToProvider(), _options.UseSmsGateway && !string.IsNullOrEmpty(x.PhoneNumber), _options.UseEmailSender.GetValueOrDefault(false) && !string.IsNullOrEmpty(x.Email))); TwoFactorAuthenticatorViewModel twoFactorAuthenticatorViewModel = _userRepository.SingleOrDefault(selectSpecification); if (twoFactorAuthenticatorViewModel == null) { _logger.LogWarning($"No user. UserId {userId}"); return(Result.Fail <TwoFactorAuthenticatorViewModel>("no_user", "No User")); } return(Result.Ok(twoFactorAuthenticatorViewModel)); }