重命名未授权响应函数,优化身份验证失败处理逻辑
This commit is contained in:
parent
8a027bd21e
commit
0daa92a117
@ -8,6 +8,7 @@ void res_must_get(mg_connection* conn);
|
||||
void res_must_post(mg_connection* conn);
|
||||
void res_need_token(mg_connection* conn);
|
||||
void res_auth_fail(mg_connection* conn);
|
||||
void res_unauth(mg_connection* conn);
|
||||
void res_check_exist_fail(mg_connection* conn);
|
||||
void res_user_exist(mg_connection* conn);
|
||||
void res_not_exist(mg_connection* conn);
|
||||
|
@ -90,7 +90,7 @@ static void impl_repasswd(mg_connection* conn, admin_form_t* form)
|
||||
|
||||
int result;
|
||||
if (!admin_login(form->password, &result)) {
|
||||
res_auth_fail(conn);
|
||||
res_unauth(conn);
|
||||
} else if (!result) {
|
||||
res_incorrect(conn);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ int user_delete_handler(mg_connection* conn, void* cbdata)
|
||||
return 1;
|
||||
}
|
||||
if (!verify_token(form.token, secret)) {
|
||||
res_auth_fail(conn);
|
||||
res_unauth(conn);
|
||||
delete_form_dtor(&form);
|
||||
return 1;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ int user_repasswd_handler(mg_connection* conn, void* cbdata)
|
||||
return 1;
|
||||
}
|
||||
if (!verify_token(form.token, secret)) {
|
||||
res_auth_fail(conn);
|
||||
res_unauth(conn);
|
||||
repasswd_form_dtor(&form);
|
||||
return 1;
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ void res_need_token(mg_connection* conn)
|
||||
"Access-Control-Allow-Origin: *\r\n\r\n"
|
||||
"{\"error\":\"need token\"}");
|
||||
}
|
||||
void res_auth_fail(mg_connection* conn)
|
||||
void res_unauth(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\"}");
|
||||
"{\"error\":\"unauthorized\"}");
|
||||
}
|
||||
void res_check_exist_fail(mg_connection* conn)
|
||||
{
|
||||
@ -252,3 +252,12 @@ void res_need_xxx(mg_connection* conn, const char* xxx)
|
||||
"{\"error\":\"need %s\"}",
|
||||
xxx);
|
||||
}
|
||||
|
||||
void res_auth_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 authorize\"}");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user