Don't allow users to login if their account is not approved

This commit is contained in:
Pat Hartl 2023-08-11 13:40:51 -05:00
parent 0b7383b2ae
commit 6d8b87246e
2 changed files with 15 additions and 0 deletions

View file

@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using LANCommander.Services;
namespace LANCommander.Areas.Identity.Pages.Account namespace LANCommander.Areas.Identity.Pages.Account
{ {
@ -126,6 +127,19 @@ namespace LANCommander.Areas.Identity.Pages.Account
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
var settings = SettingService.GetSettings();
if (settings.Authentication.RequireApproval)
{
var user = await _userManager.FindByNameAsync(Input.UserName);
if (user != null && !user.Approved)
{
ModelState.AddModelError(string.Empty, "Your account must be approved by an administrator.");
return Page();
}
}
// This doesn't count login failures towards account lockout // This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, set lockoutOnFailure: true // To enable password failures to trigger account lockout, set lockoutOnFailure: true
var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: false); var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: false);

View file

@ -13,6 +13,7 @@
public class LANCommanderAuthenticationSettings public class LANCommanderAuthenticationSettings
{ {
public bool RequireApproval { get; set; } = false;
public string TokenSecret { get; set; } = ""; public string TokenSecret { get; set; } = "";
public int TokenLifetime { get; set; } = 30; public int TokenLifetime { get; set; } = 30;
public bool PasswordRequireNonAlphanumeric { get; set; } public bool PasswordRequireNonAlphanumeric { get; set; }