|
@@ -25,7 +25,7 @@
|
|
|
|
|
|
#include "goahead.h"
|
|
|
#include "user.h"
|
|
|
-
|
|
|
+#include "cJSON.h"
|
|
|
#if ME_GOAHEAD_AUTH
|
|
|
|
|
|
#if ME_COMPILER_HAS_PAM
|
|
@@ -535,23 +535,57 @@ static void loginServiceProc(Webs *wp)
|
|
|
assert(wp);
|
|
|
route = wp->route;
|
|
|
assert(route);
|
|
|
-
|
|
|
+ char *pStr;
|
|
|
+ cJSON * root = cJSON_CreateObject();
|
|
|
+ cJSON * data = cJSON_CreateObject();
|
|
|
+ cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
+ cJSON_AddStringToObject(root, "msg", "");
|
|
|
+ cJSON_AddNumberToObject(root, "code", 200);
|
|
|
if (websLoginUser(wp, websGetVar(wp, "username", ""), websGetVar(wp, "password", ""))) {
|
|
|
/* If the application defines a referrer session var, redirect to that */
|
|
|
char *referrer;
|
|
|
- if ((referrer = websGetSessionVar(wp, "referrer", 0)) != 0) {
|
|
|
- websRedirect(wp, referrer);
|
|
|
- } else {
|
|
|
- websRedirectByStatus(wp, HTTP_CODE_OK);
|
|
|
- }
|
|
|
+ // if ((referrer = websGetSessionVar(wp, "referrer", 0)) != 0) {
|
|
|
+ // websRedirect(wp, referrer);
|
|
|
+ // } else {
|
|
|
+ // websRedirectByStatus(wp, HTTP_CODE_OK);
|
|
|
+ // }
|
|
|
+
|
|
|
+ cJSON_AddNumberToObject(root, "code", 200);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
websSetSessionVar(wp, "loginStatus", "ok");
|
|
|
} else {
|
|
|
- if (route->askLogin) {
|
|
|
- (route->askLogin)(wp);
|
|
|
- }
|
|
|
- websSetSessionVar(wp, "loginStatus", "failed");
|
|
|
- websRedirectByStatus(wp, HTTP_CODE_UNAUTHORIZED);
|
|
|
+ // if (route->askLogin) {
|
|
|
+ // (route->askLogin)(wp);
|
|
|
+ // }
|
|
|
+ // websSetSessionVar(wp, "loginStatus", "failed");
|
|
|
+ // websRedirectByStatus(wp, HTTP_CODE_UNAUTHORIZED);
|
|
|
+ cJSON_AddNumberToObject(root, "code", 201);
|
|
|
}
|
|
|
+
|
|
|
+ pStr = cJSON_PrintUnformatted(root);
|
|
|
+
|
|
|
+ printf("---> cJSON Str: %d \n%s\n", strlen(pStr), pStr);
|
|
|
+ websSetStatus(wp, 200);
|
|
|
+ websWriteHeaders(wp, -1, 0); //Set length to -1 if unknown and transfer-chunk-encoding will be employed.
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
+ int ret;
|
|
|
+ ret = websWrite(wp, "%s", pStr);
|
|
|
+ if(ret < 0)
|
|
|
+ printf("websWrite error\n");
|
|
|
+
|
|
|
+ ret = websFlush(wp, 1); //wait for all data to be written to the socket
|
|
|
+ if(ret != 1)
|
|
|
+ printf("websFlush error, ret = %d\n", ret);
|
|
|
+
|
|
|
+ websDone(wp);
|
|
|
+
|
|
|
+ if(pStr)
|
|
|
+ wfree(pStr);
|
|
|
+ if(root)
|
|
|
+ cJSON_Delete(root);
|
|
|
}
|
|
|
|
|
|
|