-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_model.php
More file actions
32 lines (23 loc) · 882 Bytes
/
Copy pathtrain_model.php
File metadata and controls
32 lines (23 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
declare(strict_types=1);
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/app/helpers.php';
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/app/auth.php';
require_once __DIR__ . '/train_recognizer.php';
header('Content-Type: application/json; charset=UTF-8');
try {
$user = require_roles(['admin']);
if (!is_post()) {
throw new RuntimeException('Only POST requests are allowed.', 405);
}
if (!verify_csrf_token($_POST['csrf_token'] ?? null)) {
throw new RuntimeException('Invalid session token. Please refresh the page.', 419);
}
$result = train_face_recognizer();
http_response_code($result['success'] ? 200 : 500);
echo json_encode($result);
} catch (Throwable $e) {
http_response_code(500);
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}