moved things around added delay admin page styling.
This commit is contained in:
@@ -32,7 +32,7 @@ namespace CarCareTracker.Helper
|
||||
{
|
||||
userId = int.Parse(storedUserId);
|
||||
}
|
||||
bool isRootUser = user.IsInRole(nameof(UserData.IsRootUser));
|
||||
bool isRootUser = user.IsInRole(nameof(UserData.IsRootUser)) || userId == -1;
|
||||
if (isRootUser)
|
||||
{
|
||||
try
|
||||
@@ -85,6 +85,16 @@ namespace CarCareTracker.Helper
|
||||
}
|
||||
public UserConfig GetUserConfig(ClaimsPrincipal user)
|
||||
{
|
||||
var serverConfig = new UserConfig
|
||||
{
|
||||
EnableCsvImports = bool.Parse(_config[nameof(UserConfig.EnableCsvImports)]),
|
||||
UseDarkMode = bool.Parse(_config[nameof(UserConfig.UseDarkMode)]),
|
||||
UseMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]),
|
||||
UseDescending = bool.Parse(_config[nameof(UserConfig.UseDescending)]),
|
||||
EnableAuth = bool.Parse(_config[nameof(UserConfig.EnableAuth)]),
|
||||
HideZero = bool.Parse(_config[nameof(UserConfig.HideZero)]),
|
||||
UseUKMPG = bool.Parse(_config[nameof(UserConfig.UseUKMPG)])
|
||||
};
|
||||
int userId = 0;
|
||||
if (user != null)
|
||||
{
|
||||
@@ -95,26 +105,16 @@ namespace CarCareTracker.Helper
|
||||
}
|
||||
} else
|
||||
{
|
||||
return new UserConfig();
|
||||
return serverConfig;
|
||||
}
|
||||
return _cache.GetOrCreate<UserConfig>($"userConfig_{userId}", entry =>
|
||||
{
|
||||
entry.SlidingExpiration = TimeSpan.FromHours(1);
|
||||
var serverConfig = new UserConfig
|
||||
{
|
||||
EnableCsvImports = bool.Parse(_config[nameof(UserConfig.EnableCsvImports)]),
|
||||
UseDarkMode = bool.Parse(_config[nameof(UserConfig.UseDarkMode)]),
|
||||
UseMPG = bool.Parse(_config[nameof(UserConfig.UseMPG)]),
|
||||
UseDescending = bool.Parse(_config[nameof(UserConfig.UseDescending)]),
|
||||
EnableAuth = bool.Parse(_config[nameof(UserConfig.EnableAuth)]),
|
||||
HideZero = bool.Parse(_config[nameof(UserConfig.HideZero)]),
|
||||
UseUKMPG = bool.Parse(_config[nameof(UserConfig.UseUKMPG)])
|
||||
};
|
||||
if (!user.Identity.IsAuthenticated)
|
||||
{
|
||||
return serverConfig;
|
||||
}
|
||||
bool isRootUser = user.IsInRole(nameof(UserData.IsRootUser));
|
||||
bool isRootUser = user.IsInRole(nameof(UserData.IsRootUser)) || userId == -1;
|
||||
if (isRootUser)
|
||||
{
|
||||
return serverConfig;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using CarCareTracker.External.Interfaces;
|
||||
using CarCareTracker.Helper;
|
||||
using CarCareTracker.Models;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Security.Cryptography;
|
||||
@@ -31,11 +32,16 @@ namespace CarCareTracker.Logic
|
||||
private readonly IUserRecordDataAccess _userData;
|
||||
private readonly ITokenRecordDataAccess _tokenData;
|
||||
private readonly IMailHelper _mailHelper;
|
||||
public LoginLogic(IUserRecordDataAccess userData, ITokenRecordDataAccess tokenData, IMailHelper mailHelper)
|
||||
private IMemoryCache _cache;
|
||||
public LoginLogic(IUserRecordDataAccess userData,
|
||||
ITokenRecordDataAccess tokenData,
|
||||
IMailHelper mailHelper,
|
||||
IMemoryCache memoryCache)
|
||||
{
|
||||
_userData = userData;
|
||||
_tokenData = tokenData;
|
||||
_mailHelper = mailHelper;
|
||||
_cache = memoryCache;
|
||||
}
|
||||
public bool CheckIfUserIsValid(int userId)
|
||||
{
|
||||
@@ -275,6 +281,7 @@ namespace CarCareTracker.Logic
|
||||
existingUserConfig.UserPasswordHash = hashedPassword;
|
||||
}
|
||||
File.WriteAllText(StaticHelper.UserConfigPath, JsonSerializer.Serialize(existingUserConfig));
|
||||
_cache.Remove("userConfig_-1");
|
||||
return true;
|
||||
}
|
||||
public bool DeleteRootUserCredentials()
|
||||
@@ -288,6 +295,8 @@ namespace CarCareTracker.Logic
|
||||
existingUserConfig.UserNameHash = string.Empty;
|
||||
existingUserConfig.UserPasswordHash = string.Empty;
|
||||
}
|
||||
//clear out the cached config for the root user.
|
||||
_cache.Remove("userConfig_-1");
|
||||
File.WriteAllText(StaticHelper.UserConfigPath, JsonSerializer.Serialize(existingUserConfig));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
}
|
||||
@model AdminViewModel
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<span class="display-4">Admin Panel</span>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-5">
|
||||
<div class="row">
|
||||
@@ -38,7 +42,7 @@
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr class="d-flex">
|
||||
<th scope="col" class="col-4">UserName</th>
|
||||
<th scope="col" class="col-4">Username</th>
|
||||
<th scope="col" class="col-2">Is Admin</th>
|
||||
<th scope="col" class="col-4">Reset Password</th>
|
||||
<th scope="col" class="col-2">Delete</th>
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
if (result.isConfirmed) {
|
||||
$.post('/Login/CreateLoginCreds', { userName: result.value.username, password: result.value.password }, function (data) {
|
||||
if (data) {
|
||||
window.location.href = '/Login';
|
||||
setTimeout(function () { window.location.href = '/Login' }, 500);
|
||||
} else {
|
||||
errorToast("An error occurred, please try again later.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user