Compare commits

..

5 Commits

5 changed files with 143 additions and 166 deletions

View File

@ -11,21 +11,22 @@ public static partial class APIHandler
//============MISC=================
.Map("/updatecache",cache=>{
cache.Run(async runner=>{
_ = await UpdateCache();
await WriteJsonResponse(runner,StatusCodes.Status200OK,"Cache Updated.");
await UpdateCache();
await runner.WriteJsonResponse(StatusCodes.Status200OK,"Cache Updated.");
});
})
//===========UNITS=================
.Map("/getunits", units =>{
units.Run(async runner=>{
if (!await RequestValidated(runner,2)) return;
await WriteJsonResponse(runner,StatusCodes.Status200OK,"Success",Deployments);
units.Run(async runner=>
{
if (!await runner.RequestValidated(2)) return;
await runner.WriteJsonResponse( StatusCodes.Status200OK, "Success", Deployments);
});
})
.Map("/chunit", unit =>{
unit.Run(async runner=>{
if (!await RequestValidated(runner, 2, "POST", true)) return;
if(await TryGetBodyJsonAsync(runner, ["deplid", "unitkerja"], CTS.Token) is Dictionary<string, JsonElement> InElement)
if (!await runner.RequestValidated(2, "POST", true)) return;
if(await runner.TryGetBodyJsonAsync(["deplid", "unitkerja"], CTS.Token) is Dictionary<string, JsonElement> InElement)
{
Deployment CorrectDeployment = new(
InElement["deplid"].GetInt16(),
@ -33,13 +34,13 @@ public static partial class APIHandler
);
if (CorrectDeployment.UnitKerja.Length < 1)
{
await WriteJsonResponse(runner,StatusCodes.Status400BadRequest, "Unit Kerja can't be empty string.");
await runner.WriteJsonResponse(StatusCodes.Status400BadRequest, "Unit Kerja can't be empty string.");
return;
}
int i = Deployments.FindIndex(depl=>depl.DeplID == CorrectDeployment.DeplID);
if(i<0)
{
await WriteJsonResponse(runner,StatusCodes.Status404NotFound,"Deployment ID not found.");
await runner.WriteJsonResponse(StatusCodes.Status404NotFound,"Deployment ID not found.");
return;
}
_ = await RunNonQueryAsync(CS,"UPDATE deployment SET unitkerja = @uk WHERE deplid = @id",Comm=>{
@ -47,19 +48,19 @@ public static partial class APIHandler
Comm.Parameters.AddWithValue("@uk", CorrectDeployment.UnitKerja);
},CTS.Token);
Deployments[i] = CorrectDeployment;
await WriteJsonResponse(runner,StatusCodes.Status202Accepted,"Data updated.",Deployments[i]);
await runner.WriteJsonResponse(StatusCodes.Status202Accepted,"Data updated.",Deployments[i]);
}
});
})
.Map("/addunit", unit =>{
unit.Run(async runner=>{
if (!await RequestValidated(runner, 2, "POST", true)) return;
if(await TryGetBodyJsonAsync(runner, ["unitkerja"], CTS.Token) is Dictionary<string, JsonElement> InElement)
if (!await runner.RequestValidated(2, "POST", true)) return;
if(await runner.TryGetBodyJsonAsync(["unitkerja"], CTS.Token) is Dictionary<string, JsonElement> InElement)
{
string UnitKerja = InElement["unitkerja"].GetString() ?? "";
if (UnitKerja.Length < 1)
{
await WriteJsonResponse(runner,StatusCodes.Status400BadRequest, "Unit Kerja can't be empty string.");
await runner.WriteJsonResponse(StatusCodes.Status400BadRequest, "Unit Kerja can't be empty string.");
return;
}
short DeplID = (short)await RunScalarAsync(CS,"INSERT INTO deployment OUTPUT INSERTED.deplid VALUES (@uk)",Comm=>{
@ -68,30 +69,30 @@ public static partial class APIHandler
Deployment Inserted = new(DeplID,UnitKerja);
Deployments.Add(Inserted);
// EventsMarker.CacheUpdates = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString("X");
await WriteJsonResponse(runner,StatusCodes.Status201Created,"Data Created.",Inserted);
await runner.WriteJsonResponse(StatusCodes.Status201Created,"Data Created.",Inserted);
}
});
})
//============AGENTS==============
.Map("/getagents", agents=>{
agents.Run(async runner=>{
if (!await RequestValidated(runner,2)) return;
await WriteJsonResponse(runner,StatusCodes.Status200OK,"Success",Agents);
if (!await runner.RequestValidated(2)) return;
await runner.WriteJsonResponse(StatusCodes.Status200OK,"Success",Agents);
});
})
.Map("/addagent", agent=>{
agent.Run(async runner=>{
if (!await RequestValidated(runner, 1, "POST", true)) return;
if (await TryGetBodyJsonAsync(runner, ["agentid", "name", "jabatan", "deplid", "skangkat", "tmt", "skper", "tgper", "vision", "mission", "photo", "createuser", "uname", "pass", "level"], CTS.Token) is Dictionary<string, JsonElement> InElement)
if (!await runner.RequestValidated(1, "POST", true)) return;
if (await runner.TryGetBodyJsonAsync(["agentid", "name", "jabatan", "deplid", "skangkat", "tmt", "skper", "tgper", "vision", "mission", "photo", "createuser", "uname", "pass", "level"], CTS.Token) is Dictionary<string, JsonElement> InElement)
{
string AgentID = InElement["agentid"].GetString() ?? string.Empty;
string Name = InElement["nama"].GetString() ?? string.Empty;
string Name = InElement["name"].GetString() ?? string.Empty;
string Jabatan = InElement["jabatan"].GetString() ?? string.Empty;
short DeploymentID = InElement["deplid"].GetInt16();
string SKAngkat = InElement["skangkat"].GetString() ?? string.Empty;
DateTime TMT = DateTime.Parse(InElement["tmt"].GetString() ?? "1970-01-01");
DateOnly TMT = DateOnly.Parse(InElement["tmt"].GetString()?[..10] ?? "1970-01-01");
string SKPer = InElement["skper"].GetString() ?? string.Empty;
DateTime? TGPer = InElement["tgper"].GetString()?.Length > 0 ? DateTime.Parse(InElement["tgper"].GetString()!) : null;
DateOnly? TGPer = InElement["tgper"].GetString()?.Length > 0 ? DateOnly.Parse(InElement["tgper"].GetString()![..10]) : null;
string Vision = InElement["vision"].GetString() ?? "-";
string Mission = InElement["mission"].GetString() ?? "-";
string Photo = InElement["photo"].GetString() ?? string.Empty;
@ -111,9 +112,10 @@ public static partial class APIHandler
(CreateUser && UName.Equals(string.Empty)) ||
(CreateUser && PlainPass.Equals(string.Empty)) ||
(!Photo.Equals(string.Empty) && !PhotoMatch.Success) ||
(await RequestValidated(runner, Level, "POST")))
(!await runner.RequestValidated(Level, "POST"))
)
{
await WriteJsonResponse(runner, StatusCodes.Status400BadRequest, "One or more input(s) are not acceptable, in an unsupported format, or an attempt to create user account of a higher level than the creator is made.");
await runner.WriteJsonResponse( StatusCodes.Status400BadRequest, "One or more input(s) are not acceptable, in an unsupported format, or an attempt to create user account of a higher level than the creator is made.");
return;
}
if (!Photo.Equals(string.Empty))
@ -127,12 +129,13 @@ public static partial class APIHandler
if (!File.Exists(PhotoPath)) await File.WriteAllBytesAsync(PhotoPath, ImageBytes, CTS.Token);
PhotoURL = Path.Combine("/assets/images/uploads", PhotoFileName);
}
Agent NewAgent = new(AgentID, Name, Jabatan, DeploymentID, SKAngkat, TMT, SKPer.Length == 0 ? null : SKPer, SKPer.Length == 0 ? null : TGPer, Vision, Mission, Photo.Length == 0 ? null : PhotoURL);
await RunTransactionAsync(CS, async (Conn, Trans) =>
{
using (SqlCommand CreateAgent = Conn.CreateCommand())
{
CreateAgent.Transaction = Trans;
CreateAgent.CommandText = "INSERT INTO agents VALUE(@agid, @nama, @jabt, @deid, @skng, @tmt, @skpr, @tmpr, @visi, @misi, @poto)";
CreateAgent.CommandText = "INSERT INTO agents VALUES(@agid, @nama, @jabt, @deid, @skng, @tmt, @skpr, @tmpr, @visi, @misi, @poto)";
CreateAgent.Parameters.AddWithValue("@agid", AgentID);
CreateAgent.Parameters.AddWithValue("@nama", Name);
CreateAgent.Parameters.AddWithValue("@jabt", Jabatan);
@ -163,7 +166,8 @@ public static partial class APIHandler
}, CTS.Token
);
string OutMessage = CreateUser ? "New Agent and respective User Account created" : "New Agent created. User account creation is possible.";
await WriteJsonResponse(runner, StatusCodes.Status201Created, OutMessage);
await runner.WriteJsonResponse(StatusCodes.Status201Created, OutMessage, CreateUser?new SafeUser(UName,AgentID,Level,true):NewAgent);
// await runner.WriteJsonResponse(200, "OK", NewAgent);
}
});
})

61
Auth.cs
View File

@ -30,40 +30,44 @@ public static class Auth
internal static void Handle(IApplicationBuilder App)
{
App
.Map("/logout", logout =>{
logout.Run(async runner=>{
.Map("/logout", logout =>
{
logout.Run(async runner =>
{
if (!HttpMethods.IsGet(runner.Request.Method) || runner.Request.HasJsonContentType() || runner.Request.HasFormContentType)
{
await WriteJsonResponse(runner,StatusCodes.Status400BadRequest,"Improper request to log out.");
await runner.WriteJsonResponse(StatusCodes.Status400BadRequest, "Improper request to log out.");
return;
}
runner.Response.Cookies.Append("session", "", Delete);
if (runner.Items.ContainsKey("AuthorizedUser"))
{
await WriteJsonResponse(runner,StatusCodes.Status200OK,"Log out successful. Authorisation token deleted.");
await runner.WriteJsonResponse(StatusCodes.Status200OK, "Log out successful. Authorisation token deleted.");
}
else
{
await WriteJsonResponse(runner,StatusCodes.Status200OK,"No user to log out. Authorisation token does not exists.");
await runner.WriteJsonResponse(StatusCodes.Status200OK, "No user to log out. Authorisation token does not exists.");
}
});
})
.Map("/login", login =>{
login.Run(async runner=>{
.Map("/login", login =>
{
login.Run(async runner =>
{
if (runner.Items.ContainsKey("AuthorizedUser"))
{
await WriteJsonResponse(runner,StatusCodes.Status409Conflict,"Log in not allowed when an authorized user is already logged in.");
await runner.WriteJsonResponse(StatusCodes.Status409Conflict, "Log in not allowed when an authorized user is already logged in.");
}
else if (runner.Request.ContentType != "application/json")
{
await WriteJsonResponse(runner,StatusCodes.Status400BadRequest,"Request Content-Type mismatch.");
await runner.WriteJsonResponse(StatusCodes.Status400BadRequest, "Request Content-Type mismatch.");
}
else
{
LoginUser LoginInfo = (await runner.Request.ReadFromJsonAsync(SGContext.Default.LoginUser))!;
if (LoginInfo.Username is null || LoginInfo.Password is null)
{
await WriteJsonResponse(runner,StatusCodes.Status401Unauthorized,"No valid user information provided.");
await runner.WriteJsonResponse(StatusCodes.Status401Unauthorized, "No valid user information provided.");
return;
}
string SHA256Pass = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(LoginInfo.Password)));
@ -73,40 +77,61 @@ public static class Auth
string LoggedInBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(LoggedIn, SGContext.Default.SafeUser)));
string Signature = Convert.ToBase64String(SHA256.HashData(Encoding.UTF8.GetBytes(LoggedInBase64 + SecretKey)));
runner.Response.Cookies.Append("session", $"{LoggedInBase64}.{Signature}", HttpOnly);
await WriteJsonResponse(runner,StatusCodes.Status200OK,"User authorised. Authorisation token created.",LoggedIn);
await runner.WriteJsonResponse(StatusCodes.Status200OK, "User authorised. Authorisation token created.", LoggedIn);
}
else
{
await WriteJsonResponse(runner,StatusCodes.Status401Unauthorized,"Provided user information cannot be authorized");
await runner.WriteJsonResponse(StatusCodes.Status401Unauthorized, "Provided user information cannot be authorized");
}
}
});
})
.Map("/gate", auth =>{
auth.Run(async runner=>{
.Map("/gate", auth =>
{
auth.Run(async runner =>
{
if (runner.Request.ContentType != "application/json")
{
await WriteJsonResponse(runner,StatusCodes.Status400BadRequest,"Request Content-Type mismatch.");
await runner.WriteJsonResponse(StatusCodes.Status400BadRequest, "Request Content-Type mismatch.");
}
else
{
LoginUser LoginInfo = (await runner.Request.ReadFromJsonAsync(SGContext.Default.LoginUser))!;
if (LoginInfo.Username is null || LoginInfo.Password is null)
{
await WriteJsonResponse(runner,StatusCodes.Status401Unauthorized,"No valid user information provided.");
await runner.WriteJsonResponse(StatusCodes.Status401Unauthorized, "No valid user information provided.");
return;
}
string SHA256Pass = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(LoginInfo.Password)));
if (UserAccounts.TryGetValue(LoginInfo.Username, out User? FoundUser) && FoundUser.Password.Equals(SHA256Pass, StringComparison.InvariantCultureIgnoreCase) && FoundUser.Active)
{
await WriteJsonResponse(runner,StatusCodes.Status200OK,"User authorised. Operation may continue.",SafeUser.FromUser(FoundUser));
await runner.WriteJsonResponse(StatusCodes.Status200OK, "User authorised. Operation may continue.", SafeUser.FromUser(FoundUser));
}
else
{
await WriteJsonResponse(runner,StatusCodes.Status401Unauthorized,"Provided user information cannot be authorized");
await runner.WriteJsonResponse(StatusCodes.Status401Unauthorized, "Provided user information cannot be authorized");
}
}
});
})
.Map("/me", me =>
{
me.Run(async runner =>
{
if (TryGetUser(runner, out SafeUser user))
{
await runner.WriteJsonResponse(StatusCodes.Status200OK, "Success.", user);
}
else
{
await runner.WriteJsonResponse(StatusCodes.Status401Unauthorized, "No user session token is included with the request.");
}
});
})
.Run(async runner=>
{
await runner.WriteJsonResponse(StatusCodes.Status404NotFound);
})
;
}
}

View File

@ -53,32 +53,7 @@ internal static class Commons
CTS.Cancel();
};
}
internal static async Task WriteJsonResponse(HttpContext Context, int Status, string Message, object Data)
{
Context.Response.StatusCode = Status;
await Context.Response.WriteAsJsonAsync(new ApiResponse(Status, Message, Data), SGContext.Default.ApiResponse,cancellationToken: CTS.Token);
}
internal static async Task WriteJsonResponse(HttpContext Context, int Status, string Message)
{
Context.Response.StatusCode = Status;
await Context.Response.WriteAsJsonAsync(new SimpleApiResponse(Status, Message), SGContext.Default.SimpleApiResponse,cancellationToken: CTS.Token);
}
internal static async Task<bool> RequestValidated(HttpContext Context, int RequiredLevel = 0, string ValidMethod = "GET", bool CheckJson = false)
{
if (!ValidMethod.Equals(Context.Request.Method,StringComparison.OrdinalIgnoreCase) ||
(CheckJson && !Context.Request.HasJsonContentType()))
{
await WriteJsonResponse(Context, StatusCodes.Status405MethodNotAllowed, "Method Not Allowed.");
return false;
}
if (!Auth.IsAuthorized(Context, RequiredLevel))
{
await WriteJsonResponse(Context, StatusCodes.Status401Unauthorized, "Unauthorized.");
return false;
}
return true;
}
internal static async Task<int> RunNonQueryAsync(string ConnectionString, string SQL, Action<SqlCommand>? Configure = null, CancellationToken Token = default)
{
await using SqlConnection Conn = new(ConnectionString);
@ -117,6 +92,7 @@ internal static class Commons
{
await Tran.RollbackAsync(Token);
throw;
// if (ex.State != 255) throw; //state = 255 is custom sql error, designed just for this purpose of not rethrowing.
}
catch
@ -143,23 +119,6 @@ internal static class Commons
uuidBytes[8] = (byte)((uuidBytes[8] & 0x3F) | 0x80); // Set variant to 10xx
return Convert.ToHexString(uuidBytes).ToLower().Insert(8, "-").Insert(13, "-").Insert(18, "-").Insert(23, "-");
}
internal static async Task<Dictionary<string, JsonElement>?> TryGetBodyJsonAsync(HttpContext Context, string[] Keys, CancellationToken Token)
{
using JsonDocument BodyDoc = await JsonDocument.ParseAsync(Context.Request.Body,cancellationToken: Token);
JsonElement Element = BodyDoc.RootElement;
Dictionary<string, JsonElement>? Result = new(StringComparer.OrdinalIgnoreCase);
foreach (string Key in Keys)
{
if (!Element.TryGetProperty(Key, out JsonElement Value))
{
await WriteJsonResponse(Context, StatusCodes.Status400BadRequest,
"Bad Request. One or more required properties were not received.");
return null;
}
Result[Key] = Value.Clone();
}
return Result;
}
internal static Dictionary<string, JsonElement>? JsonElementToDict(JsonElement Element, string[] Keys)
{
Dictionary<string, JsonElement>? Result = new(StringComparer.OrdinalIgnoreCase);
@ -174,7 +133,7 @@ internal static class Commons
return Result;
}
internal static async Task<int> UpdateCache()
internal static async Task UpdateCache()
{
Console.WriteLine("Updating app cache.");
Console.Write(" Caching User Accounts... ");
@ -188,6 +147,8 @@ internal static class Commons
_ = UserAccounts.TryAdd((string)URead["uname"], new User((string)URead["uname"],(string)URead["name"],(string)URead["pass"],(byte)URead["level"],(bool)URead["active"]));
}
}
Console.WriteLine("Done.");
Console.Write(" Caching Unit Kerja... ");
FComm.CommandText = "SELECT * FROM deployment";
await using (SqlDataReader SRead = await FComm.ExecuteReaderAsync(CTS.Token).ConfigureAwait(false))
{
@ -196,6 +157,8 @@ internal static class Commons
(string)r["unitkerja"]
),CTS.Token);
}
Console.WriteLine("Done.");
Console.Write(" Caching Agents Info... ");
FComm.CommandText = "SELECT * FROM agents";
await using (SqlDataReader SRead = await FComm.ExecuteReaderAsync(CTS.Token).ConfigureAwait(false))
{
@ -213,70 +176,9 @@ internal static class Commons
r["photourl"] == DBNull.Value ? null : (string)r["photourl"]
),CTS.Token);
}
// FComm.CommandText = "SELECT shift_sched.*, shifts.name FROM shifts LEFT JOIN shift_sched ON shifts.shiftid = shift_sched.shiftid ORDER BY shifts.shiftid, [day]";
// await using (SqlDataReader SRead = await FComm.ExecuteReaderAsync(CTS.Token).ConfigureAwait(false))
// {
// ShiftSched = await SRead.ToListAsync<ShiftSchedEntry>(r=>new(
// (byte)r["shiftid"],
// (string)r["name"],
// (byte)r["schedid"],
// (byte)r["day"],
// TimeOnly.FromTimeSpan((TimeSpan)r["start"]),
// TimeOnly.FromTimeSpan((TimeSpan)r["end"])
// ),CTS.Token);
// }
Console.WriteLine("Done.");
Console.WriteLine("App cache updated.");
return 0;
// FComm.CommandText = "SELECT shift_sched.*, shifts.name FROM shifts LEFT JOIN shift_sched ON shifts.shiftid = shift_sched.shiftid ORDER BY shifts.shiftid, [day]";
// await using (SqlDataReader SRead = await FComm.ExecuteReaderAsync(CTS.Token).ConfigureAwait(false))
// {
// ShiftSched = await SRead.ToListAsync<ShiftSchedEntry>(r=>new(
// (byte)r["shiftid"],
// (string)r["name"],
// (byte)r["schedid"],
// (byte)r["day"],
// TimeOnly.FromTimeSpan((TimeSpan)r["start"]),
// TimeOnly.FromTimeSpan((TimeSpan)r["end"])
// ),CTS.Token);
// }
// FComm.CommandText = "SELECT tariffs.*, tariff_sched.schedid, tariff_sched.amount FROM tariffs LEFT JOIN tariff_sched ON tariffs.tariffid = tariff_sched.tariffid ORDER BY tariffs.tariffid";
// await using (SqlDataReader TRead = await FComm.ExecuteReaderAsync(CTS.Token).ConfigureAwait(false))
// {
// TariffSched = await TRead.ToListAsync<TariffSchedEntry>(r=>new(
// (byte)r["tariffid"],
// (string)r["name"],
// (bool)r["active"],
// r["schedid"] == DBNull.Value ? null : (byte)r["schedid"],
// r["amount"] == DBNull.Value ? null : (int)r["amount"]
// ),CTS.Token);
// }
// FComm.CommandText = "SELECT * FROM charges";
// await using (SqlDataReader CRead = await FComm.ExecuteReaderAsync(CTS.Token).ConfigureAwait(false))
// {
// Charges = await CRead.ToListAsync<Charge>(r=>new(
// (byte)r["chargid"],
// (string)r["name"],
// r["percentage"] == DBNull.Value ? null : (byte)r["percentage"],
// r["amount"] == DBNull.Value ? null : (int)r["amount"]
// ),CTS.Token);
// }
// FComm.CommandText = "SELECT * FROM packview";
// await using (SqlDataReader PRead = await FComm.ExecuteReaderAsync(CTS.Token).ConfigureAwait(false))
// {
// Packages = await PRead.ToListAsync<PackItem>(r=>new(
// (byte)r["packid"],
// (string)r["name"],
// (short)r["durinmin"],
// (int)r["price"],
// (byte)r["shiftid"],
// (string)r["shift"],
// (byte)r["schedid"],
// (byte)r["day"],
// (bool)r["active"]
// ), CTS.Token);
// }
// EventsMarker.CacheUpdates = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString("X");
return;
}
@ -334,7 +236,7 @@ internal static class DataReaderExtensions
Func<SqlDataReader, T> map,
CancellationToken cancellationToken = default)
{
var list = new List<T>();
List<T> list = [];
while (await reader.ReadAsync(cancellationToken))
{
list.Add(map(reader));
@ -342,6 +244,52 @@ internal static class DataReaderExtensions
return list;
}
}
internal static class HttpContextExtensions
{
internal static async Task<bool> RequestValidated(this HttpContext Context, int RequiredLevel = 0, string ValidMethod = "GET", bool CheckJson = false)
{
if (!ValidMethod.Equals(Context.Request.Method, StringComparison.OrdinalIgnoreCase) ||
(CheckJson && !Context.Request.HasJsonContentType()))
{
await Context.WriteJsonResponse(StatusCodes.Status405MethodNotAllowed, "Method Not Allowed.");
return false;
}
if (!Auth.IsAuthorized(Context, RequiredLevel))
{
await Context.WriteJsonResponse(StatusCodes.Status401Unauthorized, "Unauthorized.");
return false;
}
return true;
}
internal static async Task WriteJsonResponse(this HttpContext Context, int Status, string Message, object Data)
{
Context.Response.StatusCode = Status;
await Context.Response.WriteAsJsonAsync(new ApiResponse(Status, Message, Data), SGContext.Default.ApiResponse, cancellationToken: CTS.Token);
}
internal static async Task WriteJsonResponse(this HttpContext Context, int Status, string Message = "")
{
Context.Response.StatusCode = Status;
await Context.Response.WriteAsJsonAsync(new SimpleApiResponse(Status, Message), SGContext.Default.SimpleApiResponse, cancellationToken: CTS.Token);
}
internal static async Task<Dictionary<string, JsonElement>?> TryGetBodyJsonAsync(this HttpContext Context, string[] Keys, CancellationToken Token)
{
using JsonDocument BodyDoc = await JsonDocument.ParseAsync(Context.Request.Body,cancellationToken: Token);
JsonElement Element = BodyDoc.RootElement;
Dictionary<string, JsonElement>? Result = new(StringComparer.OrdinalIgnoreCase);
foreach (string Key in Keys)
{
if (!Element.TryGetProperty(Key, out JsonElement Value))
{
await Context.WriteJsonResponse(StatusCodes.Status400BadRequest,
"Bad Request. One or more required properties were not received.");
return null;
}
Result[Key] = Value.Clone();
}
return Result;
}
}
public static class Crc32
{
static readonly uint[] Table;

View File

@ -9,7 +9,7 @@ internal partial record ApiResponse(int Status, string Message, object Data);
internal partial record Deployment(short DeplID, string UnitKerja);
internal partial record LoginUser(string Username, string Password);
internal partial record PasswdUser(string Username, string PlainPassword);
internal partial record SafeUser(string Username, string Name, byte Level, bool Active) {
internal partial record SafeUser(string Username, string AgentID, byte Level, bool Active) {
internal static SafeUser FromUser(User Source)
{
return new(Source.Username, Source.Name, Source.Level, Source.Active);

View File

@ -26,7 +26,7 @@ try
};
CS = CSBuilder.ConnectionString;
Console.WriteLine($"Done.");
_ = await UpdateCache();
await UpdateCache();
Console.Write($"Configuring Kestrel Backend... ");
IWebHost host = new WebHostBuilder()
.UseKestrel(options => {