| | | 1 | | #include "auth_handler.h" |
| | | 2 | | #include "../../database/cJSON.h" |
| | | 3 | | #include "../../security/jwt.h" |
| | | 4 | | #include <string.h> |
| | | 5 | | #include <stdlib.h> |
| | | 6 | | #include <stdio.h> |
| | | 7 | | |
| | 1 | 8 | | void handle_auth_request(HttpRequest *req, HttpResponse *res) { |
| | | 9 | | // Mock kullanıcı bilgileri |
| | 1 | 10 | | int user_id = 1; |
| | 1 | 11 | | const char *username = "admin"; |
| | 1 | 12 | | const char *role = "admin"; |
| | | 13 | | // jwt.h'daki orijinal generate_auth_token fonksiyonunu çağır |
| | 1 | 14 | | char *token = generate_auth_token(user_id, username, role); |
| | 1 | 15 | | cJSON *root = cJSON_CreateObject(); |
| | 1 | 16 | | cJSON_AddStringToObject(root, "status", "authenticated"); |
| | 1 | 17 | | cJSON_AddStringToObject(root, "token", token); |
| | 1 | 18 | | cJSON_AddStringToObject(root, "role", role); |
| | 1 | 19 | | cJSON_AddStringToObject(root, "username", username); |
| | 1 | 20 | | char *json = cJSON_Print(root); |
| | 1 | 21 | | cJSON_Delete(root); |
| | 1 | 22 | | free(token); |
| | 1 | 23 | | res->status_code = 200; |
| | 1 | 24 | | strcpy(res->content_type, "application/json"); |
| | 1 | 25 | | strncpy(res->body, json, 8191); |
| | 1 | 26 | | res->body[8191] = '\0'; |
| | 1 | 27 | | free(json); |
| | 1 | 28 | | } |