public async Task <IActionResult> Get() { IEnumerable <AppsConfigurationDTO> result = null; try { logModel.LogMessage = "User Requested All App Configurations."; // Logging await _loggingServices.LogAsync(logModel); result = await _configurationDBUnitOfWork .ConfigurationDBContext .ApplicationConfigurations .Include(b => b.IntegratedApp) .Select(x => new AppsConfigurationDTO { ApplicationName = x.IntegratedApp.ApplicationName, ID = x.ID, Integrated = x.IntegratedApp.Integrated, Key = x.Key, Values = x.Values }).ToListAsync(); } catch (Exception ex) { return(new ExceptionResult(ex, _loggingServices)); } return(Ok(result)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { if (!ModelState.IsValid) { return(Page()); } var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { throw new ApplicationException($"Unable to load two-factor authentication user."); } var recoveryCode = Input.RecoveryCode.Replace(" ", string.Empty); var result = await _signInManager.TwoFactorRecoveryCodeSignInAsync(recoveryCode); if (result.Succeeded) { logModel.LogMessage = string.Format("User with ID '{0}' logged in with a recovery code.", user.Id); // Logging await _loggingServices.LogAsync(logModel); return(LocalRedirect(Url.GetLocalUrl(returnUrl))); } if (result.IsLockedOut) { logModel.LogMessage = string.Format("User with ID '{0}' account locked out.", user.Id); logModel.LogType = LogTypeEnum.Warn; // Logging await _loggingServices.LogAsync(logModel); return(RedirectToPage("./Lockout")); } else { logModel.LogMessage = string.Format("Invalid recovery code entered for user with ID '{0}' ", user.Id); logModel.LogType = LogTypeEnum.Warn; // Logging await _loggingServices.LogAsync(logModel); ModelState.AddModelError(string.Empty, "Invalid recovery code entered."); return(Page()); } }
public async Task <IActionResult> OnGetAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } if (!user.TwoFactorEnabled) { throw new ApplicationException($"Cannot generate recovery codes for user with ID '{user.Id}' as they do not have 2FA enabled."); } var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10); RecoveryCodes = recoveryCodes.ToArray(); logModel.LogMessage = string.Format("User with ID '{0}' has generated new 2FA recovery codes.", user.Id); // Logging await _loggingServices.LogAsync(logModel); return(Page()); }
public async Task <IActionResult> OnGetCallbackAsync(string returnUrl = null, string remoteError = null) { if (remoteError != null) { ErrorMessage = $"Error from external provider: {remoteError}"; return(RedirectToPage("./Login")); } var info = await _signInManager.GetExternalLoginInfoAsync(); if (info == null) { return(RedirectToPage("./Login")); } // Sign in the user with this external login provider if the user already has a login. var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent : false, bypassTwoFactor : true); if (result.Succeeded) { logModel.LogMessage = string.Format("{0} logged in with {1} provider.", info.Principal.Identity.Name, info.LoginProvider); // Logging await _loggingServices.LogAsync(logModel); return(LocalRedirect(Url.GetLocalUrl(returnUrl))); } if (result.IsLockedOut) { return(RedirectToPage("./Lockout")); } else { // If the user does not have an account, then ask the user to create an account. ReturnUrl = returnUrl; LoginProvider = info.LoginProvider; if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email)) { Input = new InputModel { Email = info.Principal.FindFirstValue(ClaimTypes.Email) }; } return(Page()); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { ReturnUrl = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberMe, lockoutOnFailure : true); if (result.Succeeded) { logModel.LogMessage = "User logged in."; // Logging await _loggingServices.LogAsync(logModel); return(LocalRedirect(Url.GetLocalUrl(returnUrl))); } if (result.RequiresTwoFactor) { return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe })); } if (result.IsLockedOut) { logModel.LogMessage = "User account locked out."; logModel.LogType = LogTypeEnum.Warn; // Logging await _loggingServices.LogAsync(logModel); return(RedirectToPage("./Lockout")); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(Page()); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> Get() { IEnumerable <IntegratedApp> apps = null; try { logModel.LogMessage = "User Requested All App URLS Configuration."; // Logging await _loggingServices.LogAsync(logModel); apps = await _configurationDBUnitOfWork.IntegratedAppRepository.GetAllAsync(); } catch (Exception ex) { return(new ExceptionResult(ex, _loggingServices)); } return(Ok(apps)); }
public async Task <IActionResult> Logout() { await _signInManager.SignOutAsync(); // Set Log Message logModel.LogMessage = "User logged out."; // Audit Log await _loggingServices.LogAsync(logModel); return(RedirectToPage("/Index")); }
public async Task <IActionResult> GetAppMenuAsync(string id, bool?mainMenu) { IEnumerable <AppMenuDTO> appMenuDTO = null; try { logModel.LogMessage = "Front End Application Request Apps Menu by Application ID : " + id; await _loggingServices.LogAsync(logModel); // Request App Menu That Has Same App ID And Doesnt have Category var filteredMenu = await _configurationDBUnitOfWork.AppMenuRepository .FindByAsync(x => x.IntegratedAppID.ToString() == id && x.AppMenuCategoryID == null && x.AppMenuLayout == null); // Filter If MainMenu Defined if (mainMenu.HasValue) { filteredMenu = filteredMenu.Where(x => x.MainMenu == mainMenu); } // Process The Data Model And Ordering appMenuDTO = filteredMenu .OrderBy(x => x.MenuOrder) .Select(x => new AppMenuDTO { MenuTitle = x.MenuTitle, MenuHref = x.MenuHref, MenuIcon = x.MenuIcon, MenuNotification = x.MenuNotification, PermittedRoles = _configurationDBUnitOfWork.ConfigurationDBContext.GetAllAppMenuRoleByMenuID(x.ID) }).ToList(); } catch (Exception ex) { return(new ExceptionResult(ex, _loggingServices)); } return(Ok(appMenuDTO)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { ReturnUrl = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = Input.UserName, Email = Input.Email, PhoneNumber = Input.PhoneNumber }; IEnumerable <Claim> claims = new List <Claim> { new Claim(JwtClaimTypes.Name, Input.UserName), new Claim(JwtClaimTypes.Email, Input.Email), new Claim(JwtClaimTypes.PhoneNumber, Input.PhoneNumber), new Claim(JwtClaimTypes.Role, AppRoleNames.ECommerce_End_User) }; var result = await _userManager.CreateAsync(user, Input.Password); // Add User To Roles result = await _userManager.AddToRoleAsync(user, AppRoleNames.ECommerce_End_User); // Add Claim To User result = await _userManager.AddClaimsAsync(user, claims); if (result.Succeeded) { logModel.LogMessage = "User created a new account with password."; // Logging await _loggingServices.LogAsync(logModel); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id.ToString(), code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(Input.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(Url.GetLocalUrl(returnUrl))); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <ConsentViewModel> BuildViewModelAsync(string returnUrl, ConsentInputModel model = null) { var request = await _interaction.GetAuthorizationContextAsync(returnUrl); if (request != null) { var client = await _clientStore.FindEnabledClientByIdAsync(request.ClientId); if (client != null) { var resources = await _resourceStore.FindEnabledResourcesByScopeAsync(request.ScopesRequested); if (resources != null && (resources.IdentityResources.Any() || resources.ApiResources.Any())) { return(CreateConsentViewModel(model, returnUrl, request, client, resources)); } else { logModel.LogMessage = string.Format("No scopes matching: {0}", request.ScopesRequested.Aggregate((x, y) => x + ", " + y)); await _loggingServices.LogAsync(logModel); } } else { logModel.LogMessage = string.Format("Invalid client id: {0}", request.ClientId); await _loggingServices.LogAsync(logModel); } } else { logModel.LogMessage = string.Format("No consent request matching request: {0}", returnUrl); await _loggingServices.LogAsync(logModel); } return(null); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } await _userManager.SetTwoFactorEnabledAsync(user, false); await _userManager.ResetAuthenticatorKeyAsync(user); logModel.LogMessage = string.Format("User with ID '{0}' has reset their authentication app key.", user.Id); // Logging await _loggingServices.LogAsync(logModel); return(RedirectToPage("./EnableAuthenticator")); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false); if (!disable2faResult.Succeeded) { throw new ApplicationException($"Unexpected error occurred disabling 2FA for user with ID '{_userManager.GetUserId(User)}'."); } logModel.LogMessage = string.Format("User with ID '{0}' has disabled 2fa.", _userManager.GetUserId(User)); // Logging await _loggingServices.LogAsync(logModel); return(RedirectToPage("./TwoFactorAuthentication")); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } if (!ModelState.IsValid) { await LoadSharedKeyAndQrCodeUriAsync(user); return(Page()); } // Strip spaces and hypens var verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty); var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync( user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode); if (!is2faTokenValid) { ModelState.AddModelError("Input.Code", "Verification code is invalid."); await LoadSharedKeyAndQrCodeUriAsync(user); return(Page()); } await _userManager.SetTwoFactorEnabledAsync(user, true); logModel.LogMessage = string.Format("User with ID '{0}' has enabled 2FA with an authenticator app.", user.Id); await _loggingServices.LogAsync(logModel); return(RedirectToPage("./GenerateRecoveryCodes")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var changePasswordResult = await _userManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword); if (!changePasswordResult.Succeeded) { foreach (var error in changePasswordResult.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(Page()); } await _signInManager.SignInAsync(user, isPersistent : false); logModel.LogMessage = "User changed their password successfully."; // Logging await _loggingServices.LogAsync(logModel); StatusMessage = "Your password has been changed."; return(RedirectToPage()); }
public override void ExecuteResult(ActionContext context) { #region Log Terminal var userScopesModel = new UserScopesModel(context.HttpContext); var logModel = new LogModel() { CurrentApplication = _exception.Source, LogException = _exception, LoggerName = _exception.Source, LogMessage = _exception.Message, LogType = LogTypeEnum.Error, UserID = userScopesModel.Subject.ToString(), UserLogin = userScopesModel.Name }; _loggingServices.LogAsync(logModel); #endregion var response = context.HttpContext.Response; var result = JsonConvert.SerializeObject(new { error = _exception.Message }); response.ContentType = "application/json"; response.StatusCode = (int)HttpStatusCode.BadRequest; response.WriteAsync(result); }