fixed login handling.

This commit is contained in:
Martin Preuss
2025-09-15 19:35:09 +02:00
parent 9f6adf7a98
commit d7145198a1

View File

@@ -112,22 +112,33 @@ AQH_MODULE *_loadSubModule(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *sessio
int _handleRequest(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sLastPathElem) int _handleRequest(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, const char *sLastPathElem)
{ {
GWEN_BUFFER *dbuf;
dbuf=GWEN_Buffer_new(0, 256, 0, 1);
AQH_ModService_AddHeader(m, "en", dbuf);
if (strcasecmp(sLastPathElem, "login")==0) if (strcasecmp(sLastPathElem, "login")==0)
return _handleRqLogin(m, rq); _handleRqLogin(m, rq);
else if (strcasecmp(sLastPathElem, "signup")==0) { else if (strcasecmp(sLastPathElem, "signup")==0) {
AQCGI_SendResponseWithStatus(rq, 501, "Not Implemented"); AQCGI_Request_SetResponseCode(rq, 501);
return GWEN_ERROR_NOT_IMPLEMENTED; AQCGI_Request_SetResponseText(rq, "Not Implemented");
} }
else if (strcasecmp(sLastPathElem, "confirm")==0) { else if (strcasecmp(sLastPathElem, "confirm")==0) {
AQCGI_SendResponseWithStatus(rq, 501, "Not Implemented"); AQCGI_Request_SetResponseCode(rq, 501);
return GWEN_ERROR_NOT_IMPLEMENTED; AQCGI_Request_SetResponseText(rq, "Not Implemented");
} }
else if (strcasecmp(sLastPathElem, "index.html")==0) else if (strcasecmp(sLastPathElem, "index.html")==0)
return _handleRqIndex(m, rq); _handleRqIndex(m, rq);
else { else {
AQCGI_SendResponseWithStatus(rq, 404, "Not Found"); AQCGI_Request_SetResponseCode(rq, 404);
return GWEN_ERROR_NOT_IMPLEMENTED; AQCGI_Request_SetResponseText(rq, "Not Found");
} }
AQH_ModService_AddFooter(m, "en", dbuf);
AQCGI_Request_SetBufferResponseBody(rq, dbuf);
AQCGI_Request_AddResponseHeaderData(rq, "Content-type: text/html");
return AQCGI_SendResponse(rq);
} }
@@ -136,8 +147,12 @@ int _handleRqIndex(AQH_MODULE *m, AQCGI_REQUEST *rq)
{ {
if (AQCGI_Request_GetRequestMethod(rq)==AQCGI_REQUEST_METHOD_GET) if (AQCGI_Request_GetRequestMethod(rq)==AQCGI_REQUEST_METHOD_GET)
return AQH_ModService_RespondWithFile(m, rq, "en", "index.html"); return AQH_ModService_RespondWithFile(m, rq, "en", "index.html");
AQCGI_SendResponseWithStatus(rq, 404, "Not Found"); else {
return GWEN_ERROR_GENERIC; DBG_ERROR(NULL, "Invalid request method %d", AQCGI_Request_GetRequestMethod(rq));
AQCGI_Request_SetResponseCode(rq, 405);
AQCGI_Request_SetResponseText(rq, "Method Not Allowed");
return GWEN_ERROR_GENERIC;
}
} }
@@ -147,17 +162,14 @@ int _handleRqLogin(AQH_MODULE *m, AQCGI_REQUEST *rq)
int rv; int rv;
if (AQCGI_Request_GetRequestMethod(rq)==AQCGI_REQUEST_METHOD_GET) if (AQCGI_Request_GetRequestMethod(rq)==AQCGI_REQUEST_METHOD_GET)
rv=AQH_ModService_RespondWithFile(m, rq, "en", "login.html"); AQH_ModService_RespondWithFile(m, rq, "en", "login.html");
else if (AQCGI_Request_GetRequestMethod(rq)==AQCGI_REQUEST_METHOD_POST) else if (AQCGI_Request_GetRequestMethod(rq)==AQCGI_REQUEST_METHOD_POST)
rv=_handleRqLoginPost(m, rq); _handleRqLoginPost(m, rq);
else { else {
DBG_ERROR(NULL, "Invalid request method %d", AQCGI_Request_GetRequestMethod(rq)); DBG_ERROR(NULL, "Invalid request method %d", AQCGI_Request_GetRequestMethod(rq));
AQCGI_SendResponseWithStatus(rq, 405, "Method No Allowed"); AQCGI_Request_SetResponseCode(rq, 405);
return GWEN_ERROR_INVALID; AQCGI_Request_SetResponseText(rq, "Method Not Allowed");
} return GWEN_ERROR_GENERIC;
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
return rv;
} }
return 0; return 0;
} }
@@ -178,6 +190,8 @@ int _handleRqLoginPost(AQH_MODULE *m, AQCGI_REQUEST *rq)
user=_getAndCheckUser(m, rq); user=_getAndCheckUser(m, rq);
if (user==NULL) { if (user==NULL) {
DBG_INFO(NULL, "here"); DBG_INFO(NULL, "here");
AQCGI_Request_SetResponseCode(rq, 500);
AQCGI_Request_SetResponseText(rq, "Internal Error");
return GWEN_ERROR_GENERIC; return GWEN_ERROR_GENERIC;
} }
@@ -187,7 +201,8 @@ int _handleRqLoginPost(AQH_MODULE *m, AQCGI_REQUEST *rq)
rv=AQH_Service_SaveUser(sv, user); rv=AQH_Service_SaveUser(sv, user);
if (rv<0) { if (rv<0) {
DBG_ERROR(NULL, "Error saving user \"%s\"", AQH_User_GetAlias(user)); DBG_ERROR(NULL, "Error saving user \"%s\"", AQH_User_GetAlias(user));
AQCGI_SendResponseWithStatus(rq, 500, "Internal Error"); AQCGI_Request_SetResponseCode(rq, 500);
AQCGI_Request_SetResponseText(rq, "Internal Error");
AQH_User_free(user); AQH_User_free(user);
return rv; return rv;
} }
@@ -205,7 +220,8 @@ int _handleRqLoginPost(AQH_MODULE *m, AQCGI_REQUEST *rq)
rv=AQH_Service_AddSession(sv, session); rv=AQH_Service_AddSession(sv, session);
if (rv<0) { if (rv<0) {
DBG_ERROR(NULL, "Error adding session for user \"%s\"", AQH_User_GetAlias(user)); DBG_ERROR(NULL, "Error adding session for user \"%s\"", AQH_User_GetAlias(user));
AQCGI_SendResponseWithStatus(rq, 500, "Internal Error"); AQCGI_Request_SetResponseCode(rq, 500);
AQCGI_Request_SetResponseText(rq, "Internal Error");
AQH_Session_free(session); AQH_Session_free(session);
AQH_User_free(user); AQH_User_free(user);
return GWEN_ERROR_INTERNAL; return GWEN_ERROR_INTERNAL;
@@ -217,7 +233,9 @@ int _handleRqLoginPost(AQH_MODULE *m, AQCGI_REQUEST *rq)
AQCGI_Request_AddResponseHeaderData(rq, GWEN_Buffer_GetStart(dbuf)); AQCGI_Request_AddResponseHeaderData(rq, GWEN_Buffer_GetStart(dbuf));
/* finish */ /* finish */
AQCGI_SendResponseWithStatus(rq, 200, "Ok"); AQCGI_Request_AddResponseHeaderData(rq, "Location: index.html");
AQCGI_Request_SetResponseCode(rq, 303);
AQCGI_Request_SetResponseText(rq, "See other");
AQH_Session_free(session); AQH_Session_free(session);
AQH_User_free(user); AQH_User_free(user);