-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.php
More file actions
62 lines (47 loc) · 1.27 KB
/
auth.php
File metadata and controls
62 lines (47 loc) · 1.27 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
require_once __DIR__ . '/db.php';
require_once __DIR__ . '/helpers.php';
function current_user(): ?array
{
if (empty($_SESSION['user_id'])) {
return null;
}
$stmt = db()->prepare('SELECT id, email, email_verified_at FROM users WHERE id = ?');
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
return $user ?: null;
}
function require_login(): void
{
if (empty($_SESSION['user_id'])) {
redirect('/login.php');
}
}
function require_email_verified(): void
{
require_login();
$user = current_user();
if (!$user || empty($user['email_verified_at'])) {
redirect('/verify_notice.php');
}
}
function latest_kyc_submission(int $userId): ?array
{
$stmt = db()->prepare('SELECT * FROM kyc_submissions WHERE user_id = ? ORDER BY submitted_at DESC LIMIT 1');
$stmt->execute([$userId]);
$submission = $stmt->fetch();
return $submission ?: null;
}
function require_kyc_approved(): void
{
require_email_verified();
$user = current_user();
if (!$user) {
redirect('/login.php');
}
$submission = latest_kyc_submission((int) $user['id']);
if (!$submission || $submission['status'] !== 'approved') {
redirect('/kyc.php');
}
}