From 0b7383b2ae24646dea853328409def0e3bf35b6a Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Fri, 11 Aug 2023 13:35:22 -0500 Subject: [PATCH] Auto approve users created when approval is not required --- .../Areas/Identity/Pages/Account/Register.cshtml.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/LANCommander/Areas/Identity/Pages/Account/Register.cshtml.cs b/LANCommander/Areas/Identity/Pages/Account/Register.cshtml.cs index 8bdd867..4715c1e 100644 --- a/LANCommander/Areas/Identity/Pages/Account/Register.cshtml.cs +++ b/LANCommander/Areas/Identity/Pages/Account/Register.cshtml.cs @@ -19,6 +19,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Logging; +using LANCommander.Services; namespace LANCommander.Areas.Identity.Pages.Account { @@ -106,12 +107,20 @@ namespace LANCommander.Areas.Identity.Pages.Account public async Task OnPostAsync(string returnUrl = null) { + var settings = SettingService.GetSettings(); + returnUrl ??= Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = CreateUser(); + if (!settings.Authentication.RequireApproval) + { + user.Approved = false; + user.ApprovedOn = DateTime.Now; + } + await _userStore.SetUserNameAsync(user, Input.UserName, CancellationToken.None); var result = await _userManager.CreateAsync(user, Input.Password);