From a50020d7a3371a284645ad0ebc98237168740ad2 Mon Sep 17 00:00:00 2001 From: flykhan Date: Wed, 25 Oct 2023 15:40:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ignore=E8=A7=84=E5=88=99:=20?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E8=B7=9F=E8=B8=AA*.cgi=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=9Bcgi/html-base=E6=88=90=E5=8A=9F=E5=AE=9E=E7=8E=B0v3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + cgi-bin/sqlite_cgi_base.c | 57 +++++++++++++++------------------------ html/login.html | 5 ++-- 3 files changed, 24 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 6110bd6..303b812 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ # Built Visual Studio Code Extensions *.vsix .vscode +*/*.cgi diff --git a/cgi-bin/sqlite_cgi_base.c b/cgi-bin/sqlite_cgi_base.c index b365776..fd6197c 100644 --- a/cgi-bin/sqlite_cgi_base.c +++ b/cgi-bin/sqlite_cgi_base.c @@ -4,12 +4,17 @@ #include "sqlite3.h" #include +// cJSON *result_json; // 用于存储查询结果 + // sqlite3的回调函数 // sqlite 每查到一条记录,就调用一次这个回调 int sql_search_callback(void *NotUsed, int argc, char **argv, char **azColName); int main(int argc, char const *argv[]) { + + // result_json = cJSON_CreateObject(); // 创建 JSON 对象 + // 连接到 SQLite 数据库 sqlite3 *db; // 声明 sqlite3 类型变量,即声明一个数据库对象 char *zErrMsg = 0; // 用于存储错误信息 @@ -80,44 +85,8 @@ int main(int argc, char const *argv[]) return 1; } - else if (rc == SQLITE_OK) - { - cJSON *result_json = cJSON_CreateObject(); - - // if ((row = mysql_fetch_row(res))) - // { - cJSON_AddNumberToObject(result_json, "code", 0); - // cJSON_AddStringToObject(result_json, "nickname", "admin"); - // } - // else - // // { - // cJSON_AddNumberToObject(result_json, "code", 1); - // cJSON_AddStringToObject(result_json, "msg", "用户名或密码错误"); - // } - - char *result_json_string = cJSON_Print(result_json); - - // 输出 JSON 结果 - printf("content-type: application/json;charset=utf-8\r\n"); - printf("\r\n"); - printf("%s\n", result_json_string); - - free(result_json_string); - } - - // // 构建 JSON 数据 - // cJSON *result_json = cJSON_CreateObject(); - // cJSON_AddItemToObject(result_json, "result", cJSON_CreateString("success")); - // cJSON_AddItemToObject(result_json, "username", - // cJSON_CreateString(username_from_frontend)); - - // 打印 JSON 数据 - // char *result_json_str = cJSON_Print(result_json); - // printf("%s\n", result_json_str); - // 释放资源 cJSON_Delete(json_buf); - // cJSON_Delete(result_json); sqlite3_close(db); return 0; @@ -133,6 +102,22 @@ int sql_search_callback(void *NotUsed, // { // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); // } + cJSON *result_json = cJSON_CreateObject(); + if (argc == 0) + { + cJSON_AddNumberToObject(result_json, "code", 1); + cJSON_AddStringToObject(result_json, "msg", "用户名或密码错误"); + } + else + cJSON_AddNumberToObject(result_json, "code", 0); + char *result_json_string = cJSON_Print(result_json); + + // 输出 JSON 结果 + printf("content-type: application/json;charset=utf-8\r\n"); + printf("\r\n"); + printf("%s\n", result_json_string); + + free(result_json_string); return SQLITE_OK; } \ No newline at end of file diff --git a/html/login.html b/html/login.html index 57ef2ec..32ade3a 100644 --- a/html/login.html +++ b/html/login.html @@ -157,10 +157,9 @@ console.log(data); if (data.code == 0) { window.localStorage.setItem("login_user", JSON.stringify(data)); - open("/zhuti.html", "_self"); + open("./zhuti.html", "_self"); } else { - // alert(data.msg); - open("/zhuti.html", "_self"); + alert(data.msg); } })