mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -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);
|
||||
if (!GetTokenTask.Base.completed) return;
|
||||
|
||||
if (GetTokenTask.Base.success) {
|
||||
if (!GetTokenTask.Base.success) {
|
||||
MainScreen_Error(&GetTokenTask.Base, "signing in");
|
||||
return;
|
||||
}
|
||||
|
||||
SignInTask_Run(&s->iptUsername.text, &s->iptPassword.text,
|
||||
&MFAScreen_Instance.iptCode.text);
|
||||
} else {
|
||||
MainScreen_Error(&GetTokenTask.Base, "signing in");
|
||||
}
|
||||
}
|
||||
|
||||
static void MainScreen_TickSignIn(struct MainScreen* s) {
|
||||
@ -945,7 +946,11 @@ static void MainScreen_TickFetchServers(struct MainScreen* s) {
|
||||
LWebTask_Tick(&FetchServersTask.Base);
|
||||
if (!FetchServersTask.Base.completed) return;
|
||||
|
||||
if (FetchServersTask.Base.success) {
|
||||
if (!FetchServersTask.Base.success) {
|
||||
MainScreen_Error(&FetchServersTask.Base, "retrieving servers list");
|
||||
return;
|
||||
}
|
||||
|
||||
s->signingIn = false;
|
||||
if (Launcher_AutoHash.length) {
|
||||
Launcher_ConnectToServer(&Launcher_AutoHash);
|
||||
@ -953,9 +958,6 @@ static void MainScreen_TickFetchServers(struct MainScreen* s) {
|
||||
} else {
|
||||
ServersScreen_SetActive();
|
||||
}
|
||||
} else {
|
||||
MainScreen_Error(&FetchServersTask.Base, "retrieving servers list");
|
||||
}
|
||||
}
|
||||
|
||||
static void MainScreen_Tick(struct LScreen* s_) {
|
||||
|
@ -233,8 +233,11 @@ static struct StringsBuffer ccCookies;
|
||||
struct GetTokenTaskData GetTokenTask;
|
||||
|
||||
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);
|
||||
} else if (String_CaselessEqualsConst(&ctx->curKey, "username")) {
|
||||
String_Copy(&GetTokenTask.username, str);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
static const cc_string url = String_FromConst("https://www.classicube.net/api/login");
|
||||
static char tokenBuffer[STRING_SIZE];
|
||||
static char userBuffer[STRING_SIZE];
|
||||
if (GetTokenTask.Base.working) return;
|
||||
|
||||
LWebTask_Reset(&GetTokenTask.Base);
|
||||
String_InitArray(GetTokenTask.token, tokenBuffer);
|
||||
String_InitArray(GetTokenTask.username, userBuffer);
|
||||
|
||||
GetTokenTask.Base.Handle = GetTokenTask_Handle;
|
||||
GetTokenTask.Base.reqID = Http_AsyncGetDataEx(&url, false, NULL, NULL, &ccCookies);
|
||||
@ -258,7 +263,6 @@ void GetTokenTask_Run(void) {
|
||||
*--------------------------------------------------------SignInTask-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
struct SignInTaskData SignInTask;
|
||||
static char userBuffer[STRING_SIZE];
|
||||
|
||||
static void SignInTask_LogError(const cc_string* str) {
|
||||
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) {
|
||||
static const cc_string url = String_FromConst("https://www.classicube.net/api/login");
|
||||
static char userBuffer[STRING_SIZE];
|
||||
cc_string args; char argsBuffer[1024];
|
||||
if (SignInTask.Base.working) return;
|
||||
|
||||
|
@ -58,6 +58,7 @@ void LWebTask_DisplayError(struct LWebTask* task, const char* action, cc_string*
|
||||
extern struct GetTokenTaskData {
|
||||
struct LWebTask Base;
|
||||
cc_string token; /* Random CSRF token for logging in. */
|
||||
cc_string username; /* Username if session is already logged in. */
|
||||
} GetTokenTask;
|
||||
void GetTokenTask_Run(void);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user