Skip to content

Commit

Permalink
Fixed Packet references for SAPI.Auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciejowski2006 committed Nov 6, 2023
1 parent bd18e79 commit 8077f5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion SAPI.Auth/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class Session
{
public static List<SessionToken> SessionTokens = new();

public static void GenerateSessionToken(Identity identity, Packet packet)
public static void GenerateSessionToken(Identity identity, HttpListenerContext context)
{
SessionToken token = new()
{
Expand Down
11 changes: 6 additions & 5 deletions SAPI_Testing/Endpoints/AuthCheck.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SAPI;
using System.Net;
using SAPI;
using SAPI.API.Utilities;
using SAPI.Auth;

Expand All @@ -8,18 +9,18 @@ public class AuthCheck : Endpoint
{
public override string url { get; } = "auth-check";

protected override void Post(ref Packet packet)
protected override void Post(HttpListenerContext context, Dictionary<string, string> parameters)
{
Json.Fetch(out AuthExt.NewAuth auth, ref packet);
Json.Fetch(out AuthExt.NewAuth auth, context);
Identity identity = new()
{
Identifier = auth.username,
Password = auth.password
};
if (identity.Verify())
Error.Page(HttpStatus.OK, ref packet);
Error.Page(HttpStatus.OK, context);
else
Error.Page(HttpStatus.Forbidden, ref packet);
Error.Page(HttpStatus.Forbidden, context);
}
}
}
16 changes: 8 additions & 8 deletions SAPI_Testing/Endpoints/AuthExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ public class AuthExt : Endpoint
{
public override string url { get; } = "auth-ext";

protected override void Get(ref Packet packet)
protected override void Get(HttpListenerContext context, Dictionary<string, string> parameters)
{
SAPI.LLAPI.Utilities.Html.HtmlResponse("<h1>GOOD</h1>", ref packet);
SAPI.LLAPI.Utilities.Html.HtmlResponse("<h1>GOOD</h1>", context);
}

protected override void Post(ref Packet packet)
protected override void Post(HttpListenerContext context, Dictionary<string, string> parameters)
{
Json.Fetch(out NewAuth auth, ref packet);
Json.Fetch(out NewAuth auth, context);

Identity identity = new()
{
Identifier = auth.username,
Password = auth.password
};
if (identity.Create())
Error.Page(HttpStatus.OK, ref packet);
Error.Page(HttpStatus.OK, context);
else
Error.Page(HttpStatus.BadRequest, ref packet);
Error.Page(HttpStatus.BadRequest, context);

Session.GenerateSessionToken(identity, packet);
Session.GenerateSessionToken(identity, context);

Cookie cookie = new("test", "test")
{
Expires = DateTime.UtcNow.AddDays(1)
};
packet.Response.AppendCookie(cookie);
context.Response.AppendCookie(cookie);
}

public record NewAuth(string username, string password);
Expand Down

0 comments on commit 8077f5a

Please sign in to comment.