mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 07:06:34 +00:00
switch to hardware string from object
This commit is contained in:
@@ -11,8 +11,8 @@ public static class Security
|
||||
public static string ToHash(this string str) =>
|
||||
Convert.ToBase64String(SHA384.HashData(Encoding.UTF8.GetBytes(str)));
|
||||
|
||||
public static string GetHWHash(HardwareInfo hardware) =>
|
||||
$"Azaion_{hardware.MacAddress}_{hardware.CPU}_{hardware.GPU}".ToHash();
|
||||
public static string GetHWHash(string hardware) =>
|
||||
$"Azaion_{hardware}_%$$$)0_".ToHash();
|
||||
|
||||
public static string GetApiEncryptionKey(string email, string password, string? hardwareHash) =>
|
||||
$"{email}-{password}-{hardwareHash}-#%@AzaionKey@%#---".ToHash();
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface IUserService
|
||||
Task RegisterUser(RegisterUserRequest request, CancellationToken cancellationToken = default);
|
||||
Task<User> ValidateUser(LoginRequest request, CancellationToken cancellationToken = default);
|
||||
Task<User?> GetByEmail(string? email, CancellationToken cancellationToken = default);
|
||||
Task UpdateHardware(string email, HardwareInfo? hardwareInfo = null, CancellationToken cancellationToken = default);
|
||||
Task UpdateHardware(string email, string? hardware = null, CancellationToken cancellationToken = default);
|
||||
Task UpdateQueueOffsets(string email, UserQueueOffsets queueOffsets, CancellationToken cancellationToken = default);
|
||||
Task<IEnumerable<User>> GetUsers(string? searchEmail, RoleEnum? searchRole, CancellationToken cancellationToken);
|
||||
Task<string> CheckHardwareHash(User user, GetResourceRequest request);
|
||||
@@ -39,10 +39,15 @@ public class UserService(IDbFactory dbFactory, ICache cache) : IUserService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<User?> GetByEmail(string? email, CancellationToken cancellationToken = default) =>
|
||||
await cache.GetFromCacheAsync(User.GetCacheKey(email),
|
||||
public async Task<User?> GetByEmail(string? email, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(email)) throw new ArgumentNullException(nameof(email));
|
||||
|
||||
return await cache.GetFromCacheAsync(User.GetCacheKey(email),
|
||||
async () => await dbFactory.Run(async db =>
|
||||
await db.Users.FirstOrDefaultAsync(x => x.Email == email, cancellationToken)));
|
||||
}
|
||||
|
||||
|
||||
public async Task<User> ValidateUser(LoginRequest request, CancellationToken cancellationToken = default) =>
|
||||
await dbFactory.Run(async db =>
|
||||
@@ -58,17 +63,12 @@ public class UserService(IDbFactory dbFactory, ICache cache) : IUserService
|
||||
});
|
||||
|
||||
|
||||
public async Task UpdateHardware(string email, HardwareInfo? hardware = null, CancellationToken cancellationToken = default)
|
||||
public async Task UpdateHardware(string email, string? hardware = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await dbFactory.RunAdmin(async db =>
|
||||
{
|
||||
var hardwareStr = hardware == null ? "" : JsonConvert.SerializeObject(hardware);
|
||||
|
||||
await db.Users.UpdateAsync(x => x.Email == email,
|
||||
u => new User
|
||||
{
|
||||
Hardware = hardwareStr
|
||||
}, token: cancellationToken);
|
||||
u => new User { Hardware = hardware }, token: cancellationToken);
|
||||
});
|
||||
cache.Invalidate(User.GetCacheKey(email));
|
||||
}
|
||||
@@ -111,8 +111,7 @@ public class UserService(IDbFactory dbFactory, ICache cache) : IUserService
|
||||
return requestHWHash;
|
||||
}
|
||||
|
||||
var userHW = JsonConvert.DeserializeObject<HardwareInfo>(user.Hardware);
|
||||
var userHWHash = Security.GetHWHash(userHW!);
|
||||
var userHWHash = Security.GetHWHash(user.Hardware);
|
||||
if (userHWHash != requestHWHash)
|
||||
throw new BusinessException(ExceptionEnum.HardwareIdMismatch);
|
||||
return userHWHash;
|
||||
|
||||
Reference in New Issue
Block a user