use client/server model
This commit is contained in:
2
OwnChar
2
OwnChar
Submodule OwnChar updated: 32708e3e26...38dc09ab12
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using OwnChar.Api.Responses;
|
using OwnChar.Base.Data.Responses;
|
||||||
using OwnChar.Model;
|
using OwnChar.Model;
|
||||||
|
using OwnChar.Server.Data.Model;
|
||||||
|
|
||||||
namespace OwnChar.ServerNew.Api.Endpoint.Implementations;
|
namespace OwnChar.ServerNew.Api.Endpoint.Implementations;
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ internal class LoginApi(ServerContext server) : IApiEndpoint
|
|||||||
|
|
||||||
private IResult Login(string username, [FromHeader(Name = "X-USER-PASSWORD")] string password)
|
private IResult Login(string username, [FromHeader(Name = "X-USER-PASSWORD")] string password)
|
||||||
{
|
{
|
||||||
if (server.Data != null && server.Data.Set<UserAccount>()?.FirstOrDefault(n => n.Username == username && n.Password == password) is UserAccount account)
|
if (server.Data != null && server.Data.Set<UserAccountDb>()?.FirstOrDefault(n => n.Username == username && n.Password == password) is UserAccountBase account)
|
||||||
return TypedResults.Ok(new LoginResponse
|
return TypedResults.Ok(new LoginResponse
|
||||||
{
|
{
|
||||||
Secret = server.Login(account),
|
Secret = server.Login(account),
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ public interface IServer
|
|||||||
bool IsLoggedIn(string secret);
|
bool IsLoggedIn(string secret);
|
||||||
|
|
||||||
[MemberNotNullWhen(true, nameof(Data))]
|
[MemberNotNullWhen(true, nameof(Data))]
|
||||||
UserAccount? GetUser(string secret);
|
UserAccountBase? GetUser(string secret);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OwnChar.ServerNew;
|
|||||||
|
|
||||||
internal class ServerContext(ISettings settings) : Api.IServer
|
internal class ServerContext(ISettings settings) : Api.IServer
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, UserAccount> users = [];
|
private readonly Dictionary<string, UserAccountBase> users = [];
|
||||||
|
|
||||||
public DbContext? Data { get; private set; }
|
public DbContext? Data { get; private set; }
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ internal class ServerContext(ISettings settings) : Api.IServer
|
|||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Login(UserAccount account)
|
public string Login(UserAccountBase account)
|
||||||
{
|
{
|
||||||
var secret = new UniquieID(UniquieIDGenerationMode.GenerateOnInit).ID;
|
var secret = new UniquieID(UniquieIDGenerationMode.GenerateOnInit).ID;
|
||||||
users.Add(secret, account);
|
users.Add(secret, account);
|
||||||
@@ -99,10 +99,10 @@ internal class ServerContext(ISettings settings) : Api.IServer
|
|||||||
throw new UnauthorizedAccessException();
|
throw new UnauthorizedAccessException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserAccount? GetUser(string secret)
|
public UserAccountBase? GetUser(string secret)
|
||||||
{
|
{
|
||||||
Log.DebugFormat("Getting user with secret {0}", secret);
|
Log.DebugFormat("Getting user with secret {0}", secret);
|
||||||
if (users.TryGetValue(secret, out UserAccount? value))
|
if (users.TryGetValue(secret, out UserAccountBase? value))
|
||||||
return value;
|
return value;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user