mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
If GET /api/login returns a username then keep track of that
This commit is contained in:
parent
e31e42c665
commit
beba09b2ef
@ -906,12 +906,13 @@ static void MainScreen_TickGetToken(struct MainScreen* s) {
|
|||||||
LWebTask_Tick(&GetTokenTask.Base);
|
LWebTask_Tick(&GetTokenTask.Base);
|
||||||
if (!GetTokenTask.Base.completed) return;
|
if (!GetTokenTask.Base.completed) return;
|
||||||
|
|
||||||
if (GetTokenTask.Base.success) {
|
if (!GetTokenTask.Base.success) {
|
||||||
SignInTask_Run(&s->iptUsername.text, &s->iptPassword.text,
|
|
||||||
&MFAScreen_Instance.iptCode.text);
|
|
||||||
} else {
|
|
||||||
MainScreen_Error(&GetTokenTask.Base, "signing in");
|
MainScreen_Error(&GetTokenTask.Base, "signing in");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SignInTask_Run(&s->iptUsername.text, &s->iptPassword.text,
|
||||||
|
&MFAScreen_Instance.iptCode.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MainScreen_TickSignIn(struct MainScreen* s) {
|
static void MainScreen_TickSignIn(struct MainScreen* s) {
|
||||||
@ -945,16 +946,17 @@ static void MainScreen_TickFetchServers(struct MainScreen* s) {
|
|||||||
LWebTask_Tick(&FetchServersTask.Base);
|
LWebTask_Tick(&FetchServersTask.Base);
|
||||||
if (!FetchServersTask.Base.completed) return;
|
if (!FetchServersTask.Base.completed) return;
|
||||||
|
|
||||||
if (FetchServersTask.Base.success) {
|
if (!FetchServersTask.Base.success) {
|
||||||
s->signingIn = false;
|
|
||||||
if (Launcher_AutoHash.length) {
|
|
||||||
Launcher_ConnectToServer(&Launcher_AutoHash);
|
|
||||||
Launcher_AutoHash.length = 0;
|
|
||||||
} else {
|
|
||||||
ServersScreen_SetActive();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MainScreen_Error(&FetchServersTask.Base, "retrieving servers list");
|
MainScreen_Error(&FetchServersTask.Base, "retrieving servers list");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
s->signingIn = false;
|
||||||
|
if (Launcher_AutoHash.length) {
|
||||||
|
Launcher_ConnectToServer(&Launcher_AutoHash);
|
||||||
|
Launcher_AutoHash.length = 0;
|
||||||
|
} else {
|
||||||
|
ServersScreen_SetActive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/LWeb.c
13
src/LWeb.c
@ -233,8 +233,11 @@ static struct StringsBuffer ccCookies;
|
|||||||
struct GetTokenTaskData GetTokenTask;
|
struct GetTokenTaskData GetTokenTask;
|
||||||
|
|
||||||
static void GetTokenTask_OnValue(struct JsonContext* ctx, const cc_string* str) {
|
static void GetTokenTask_OnValue(struct JsonContext* ctx, const cc_string* str) {
|
||||||
if (!String_CaselessEqualsConst(&ctx->curKey, "token")) return;
|
if (String_CaselessEqualsConst(&ctx->curKey, "token")) {
|
||||||
String_Copy(&GetTokenTask.token, str);
|
String_Copy(&GetTokenTask.token, str);
|
||||||
|
} else if (String_CaselessEqualsConst(&ctx->curKey, "username")) {
|
||||||
|
String_Copy(&GetTokenTask.username, str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GetTokenTask_Handle(cc_uint8* data, cc_uint32 len) {
|
static void GetTokenTask_Handle(cc_uint8* data, cc_uint32 len) {
|
||||||
@ -244,10 +247,12 @@ static void GetTokenTask_Handle(cc_uint8* data, cc_uint32 len) {
|
|||||||
void GetTokenTask_Run(void) {
|
void GetTokenTask_Run(void) {
|
||||||
static const cc_string url = String_FromConst("https://www.classicube.net/api/login");
|
static const cc_string url = String_FromConst("https://www.classicube.net/api/login");
|
||||||
static char tokenBuffer[STRING_SIZE];
|
static char tokenBuffer[STRING_SIZE];
|
||||||
|
static char userBuffer[STRING_SIZE];
|
||||||
if (GetTokenTask.Base.working) return;
|
if (GetTokenTask.Base.working) return;
|
||||||
|
|
||||||
LWebTask_Reset(&GetTokenTask.Base);
|
LWebTask_Reset(&GetTokenTask.Base);
|
||||||
String_InitArray(GetTokenTask.token, tokenBuffer);
|
String_InitArray(GetTokenTask.token, tokenBuffer);
|
||||||
|
String_InitArray(GetTokenTask.username, userBuffer);
|
||||||
|
|
||||||
GetTokenTask.Base.Handle = GetTokenTask_Handle;
|
GetTokenTask.Base.Handle = GetTokenTask_Handle;
|
||||||
GetTokenTask.Base.reqID = Http_AsyncGetDataEx(&url, false, NULL, NULL, &ccCookies);
|
GetTokenTask.Base.reqID = Http_AsyncGetDataEx(&url, false, NULL, NULL, &ccCookies);
|
||||||
@ -258,7 +263,6 @@ void GetTokenTask_Run(void) {
|
|||||||
*--------------------------------------------------------SignInTask-------------------------------------------------------*
|
*--------------------------------------------------------SignInTask-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct SignInTaskData SignInTask;
|
struct SignInTaskData SignInTask;
|
||||||
static char userBuffer[STRING_SIZE];
|
|
||||||
|
|
||||||
static void SignInTask_LogError(const cc_string* str) {
|
static void SignInTask_LogError(const cc_string* str) {
|
||||||
static char errBuffer[128];
|
static char errBuffer[128];
|
||||||
@ -299,6 +303,7 @@ static void SignInTask_Append(cc_string* dst, const char* key, const cc_string*
|
|||||||
|
|
||||||
void SignInTask_Run(const cc_string* user, const cc_string* pass, const cc_string* mfaCode) {
|
void SignInTask_Run(const cc_string* user, const cc_string* pass, const cc_string* mfaCode) {
|
||||||
static const cc_string url = String_FromConst("https://www.classicube.net/api/login");
|
static const cc_string url = String_FromConst("https://www.classicube.net/api/login");
|
||||||
|
static char userBuffer[STRING_SIZE];
|
||||||
cc_string args; char argsBuffer[1024];
|
cc_string args; char argsBuffer[1024];
|
||||||
if (SignInTask.Base.working) return;
|
if (SignInTask.Base.working) return;
|
||||||
|
|
||||||
|
@ -57,7 +57,8 @@ void LWebTask_DisplayError(struct LWebTask* task, const char* action, cc_string*
|
|||||||
|
|
||||||
extern struct GetTokenTaskData {
|
extern struct GetTokenTaskData {
|
||||||
struct LWebTask Base;
|
struct LWebTask Base;
|
||||||
cc_string token; /* Random CSRF token for logging in. */
|
cc_string token; /* Random CSRF token for logging in. */
|
||||||
|
cc_string username; /* Username if session is already logged in. */
|
||||||
} GetTokenTask;
|
} GetTokenTask;
|
||||||
void GetTokenTask_Run(void);
|
void GetTokenTask_Run(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user