mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-16 17:04:44 +01:00
Update static data, and don't hard code it
This commit is contained in:
@@ -19,6 +19,7 @@ namespace nksrv.IntlServer
|
||||
|
||||
protected override async Task HandleAsync()
|
||||
{
|
||||
if (ctx == null) throw new Exception("ctx cannot be null");
|
||||
Console.WriteLine("li-sg redirect in: " + Content);
|
||||
HttpClientHandler handler = new()
|
||||
{
|
||||
|
||||
@@ -19,18 +19,15 @@ namespace nksrv.IntlServer
|
||||
|
||||
protected override async Task HandleAsync()
|
||||
{
|
||||
|
||||
RegisterEPReq? ep = JsonConvert.DeserializeObject<RegisterEPReq>(Content);
|
||||
if (ep != null)
|
||||
{
|
||||
string? seg = ctx.GetRequestQueryData().Get("seq");
|
||||
|
||||
// check if the account already exists
|
||||
foreach (var item in JsonDb.Instance.Users)
|
||||
{
|
||||
if (item.Username == ep.account)
|
||||
{
|
||||
await WriteJsonStringAsync("{\"msg\":\"send code failed; invalid account\",\"ret\":2112,\"seq\":\"" + seg + "\"}");
|
||||
await WriteJsonStringAsync("{\"msg\":\"send code failed; invalid account\",\"ret\":2112,\"seq\":\"" + Seq + "\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -51,7 +48,7 @@ namespace nksrv.IntlServer
|
||||
JsonDb.Instance.Users.Add(user);
|
||||
|
||||
var tok = IntlHandler.CreateLauncherTokenForUser(user);
|
||||
await WriteJsonStringAsync("{\"expire\":" + tok.ExpirationTime + ",\"is_login\":false,\"msg\":\"Success\",\"register_time\":" + user.RegisterTime + ",\"ret\":0,\"seq\":\"" + seg + "\",\"token\":\"" + tok.Token + "\",\"uid\":\"" + user.ID + "\"}");
|
||||
await WriteJsonStringAsync("{\"expire\":" + tok.ExpirationTime + ",\"is_login\":false,\"msg\":\"Success\",\"register_time\":" + user.RegisterTime + ",\"ret\":0,\"seq\":\"" + Seq + "\",\"token\":\"" + tok.Token + "\",\"uid\":\"" + user.ID + "\"}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -33,9 +33,7 @@ namespace nksrv.IntlServer
|
||||
}
|
||||
}
|
||||
|
||||
string? seg = ctx.GetRequestQueryData().Get("seq");
|
||||
|
||||
await WriteJsonStringAsync("{\"msg\":\"the account does not exists!\",\"ret\":2001,\"seq\":\"" + seg + "\"}");
|
||||
await WriteJsonStringAsync("{\"msg\":\"the account does not exists!\",\"ret\":2001,\"seq\":\"" + Seq + "\"}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -12,17 +12,17 @@ namespace nksrv.IntlServer
|
||||
{
|
||||
public abstract class IntlMsgHandler
|
||||
{
|
||||
protected IHttpContext ctx;
|
||||
protected IHttpContext? ctx;
|
||||
protected string Content = "";
|
||||
protected User? User;
|
||||
protected string? Seq;
|
||||
protected string Seq = "";
|
||||
protected AccessToken? UsedToken;
|
||||
public abstract bool RequiresAuth { get; }
|
||||
public async Task HandleAsync(IHttpContext ctx)
|
||||
{
|
||||
this.ctx = ctx;
|
||||
Content = await ctx.GetRequestBodyAsStringAsync();
|
||||
Seq = ctx.GetRequestQueryData().Get("seq");
|
||||
Seq = ctx.GetRequestQueryData().Get("seq") ?? "";
|
||||
if (RequiresAuth)
|
||||
{
|
||||
var x = JsonConvert.DeserializeObject<AuthPkt>(Content);
|
||||
@@ -74,7 +74,6 @@ namespace nksrv.IntlServer
|
||||
await HandleAsync();
|
||||
}
|
||||
protected abstract Task HandleAsync();
|
||||
|
||||
protected async Task WriteJsonStringAsync(string data)
|
||||
{
|
||||
if (ctx != null)
|
||||
@@ -83,10 +82,11 @@ namespace nksrv.IntlServer
|
||||
ctx.Response.ContentEncoding = null;
|
||||
ctx.Response.ContentType = "application/json";
|
||||
ctx.Response.ContentLength64 = bt.Length;
|
||||
await ctx.Response.OutputStream.WriteAsync(bt, 0, bt.Length, ctx.CancellationToken);
|
||||
await ctx.Response.OutputStream.WriteAsync(bt, ctx.CancellationToken);
|
||||
await ctx.Response.OutputStream.FlushAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public class ChannelInfo
|
||||
{
|
||||
public string openid { get; set; } = "";
|
||||
|
||||
@@ -20,10 +20,7 @@ namespace nksrv.IntlServer
|
||||
|
||||
protected override async Task HandleAsync()
|
||||
{
|
||||
var str = await ctx.GetRequestBodyAsStringAsync();
|
||||
|
||||
string? seg = ctx.GetRequestQueryData().Get("seq");
|
||||
await WriteJsonStringAsync(JsonToReturn.Replace("((SEGID))", seg));
|
||||
await WriteJsonStringAsync(JsonToReturn.Replace("((SEGID))", Seq));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,21 +22,19 @@ namespace nksrv.IntlServer
|
||||
SendCodeRequest? ep = JsonConvert.DeserializeObject<SendCodeRequest>(Content);
|
||||
if (ep != null)
|
||||
{
|
||||
string? seg = ctx.GetRequestQueryData().Get("seq");
|
||||
|
||||
// check if the account already exists
|
||||
|
||||
foreach (var item in JsonDb.Instance.Users)
|
||||
{
|
||||
if (item.Username == ep.account)
|
||||
{
|
||||
await WriteJsonStringAsync("{\"msg\":\"send code failed; invalid account\",\"ret\":2112,\"seq\":\"" + seg + "\"}");
|
||||
await WriteJsonStringAsync("{\"msg\":\"send code failed; invalid account\",\"ret\":2112,\"seq\":\"" + Seq + "\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// pretend that we sent the code
|
||||
await WriteJsonStringAsync("{\"expire_time\":898,\"msg\":\"Success\",\"ret\":0,\"seq\":\"" + seg + "\"}");
|
||||
await WriteJsonStringAsync("{\"expire_time\":898,\"msg\":\"Success\",\"ret\":0,\"seq\":\"" + Seq + "\"}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user