255 lines
8.1 KiB
C
255 lines
8.1 KiB
C
#include "server/types.h"
|
|
#include <server/response.h>
|
|
|
|
#include <civetweb.h>
|
|
|
|
void res_null_req(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 400 Bad Request\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"null request\"}");
|
|
}
|
|
void res_must_get(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 405 Method Not Allowed\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"must send get request\"}");
|
|
}
|
|
void res_must_post(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 405 Method Not Allowed\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"must send post request\"}");
|
|
}
|
|
void res_need_token(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 400 Bad Request\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"need token\"}");
|
|
}
|
|
void res_auth_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 401 Unauthorized\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"auth failed\"}");
|
|
}
|
|
void res_check_exist_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"failed to check user existence\"}");
|
|
}
|
|
void res_user_exist(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 409 Conflict\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"user already exists\"}");
|
|
}
|
|
void res_not_exist(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 404 Not Found\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"user does not exist\"}");
|
|
}
|
|
void res_check_permission_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"failed to check user permission\"}");
|
|
}
|
|
void res_permission_denied(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 403 Forbidden\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"permission denied\"}");
|
|
}
|
|
void res_need_user_id(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 400 Bad Request\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"need user_id\"}");
|
|
}
|
|
void res_need_password(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 400 Bad Request\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"need password\"}");
|
|
}
|
|
void res_(mg_connection* conn);
|
|
void res_(mg_connection* conn);
|
|
void res_(mg_connection* conn);
|
|
void res_(mg_connection* conn);
|
|
|
|
|
|
void res_delete_account_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"failed to delete account\"}");
|
|
}
|
|
void res_delete_account(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 200 OK\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"success\":\"delete account success\"}");
|
|
}
|
|
|
|
void res_login_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"failed to login\"}");
|
|
}
|
|
void res_incorrect(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 401 Unauthorized\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"incorrect password or user id\"}");
|
|
}
|
|
void res_login(mg_connection* conn, const char* token)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 200 OK\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"success\":\"login success\", \"token\":\"%s\"}",
|
|
token);
|
|
}
|
|
|
|
void res_register_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"failed to register\"}");
|
|
}
|
|
void res_register(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 200 OK\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"success\":\"registration success\"}");
|
|
}
|
|
|
|
void res_repasswd_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"failed to repasswd account\"}");
|
|
}
|
|
void res_repasswd(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 200 OK\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"success\":\"repasswd account success\"}");
|
|
}
|
|
|
|
void res_logout_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"failed to logout\"}");
|
|
}
|
|
void res_logout(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 200 OK\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"success\":\"logout success\"}");
|
|
}
|
|
|
|
void res_permission(mg_connection* conn, int permission)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 200 OK\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"success\":\"query success\", \"permission\":\"%d\"}",
|
|
permission);
|
|
}
|
|
|
|
void res_repermission_fail(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 500 Internal Server Error\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"failed to repermission\"}");
|
|
}
|
|
void res_repermission(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 200 OK\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"success\":\"repermission success\"}");
|
|
}
|
|
void res_need_action(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 400 Bad Request\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"need action specification\"}");
|
|
}
|
|
|
|
void res_bad_action(mg_connection* conn)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 400 Bad Request\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"bad action\"}");
|
|
}
|
|
|
|
void res_need_xxx(mg_connection* conn, const char* xxx)
|
|
{
|
|
mg_printf(conn,
|
|
"HTTP/1.1 400 Bad Request\r\n"
|
|
"Content-Type: application/json\r\n"
|
|
"Access-Control-Allow-Origin: *\r\n\r\n"
|
|
"{\"error\":\"need %s\"}",
|
|
xxx);
|
|
}
|