-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadmin.php
More file actions
98 lines (63 loc) · 2.36 KB
/
Copy pathadmin.php
File metadata and controls
98 lines (63 loc) · 2.36 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
$this->on('cockpit.account.fields', function(&$fields, &$account) {
$userId = $this->module('cockpit')->getUser('_id');
if ($userId && isset($account['_id']) && $account['_id'] == $userId && !isset($account['twofa_secret'])) {
$tfa = new \RobThree\Auth\TwoFactorAuth($this['app.name']);
$account['twofa_secret'] = $tfa->createSecret(160);
}
});
$this->on('cockpit.account.panel', function(&$account) {
$userId = $this->module('cockpit')->getUser('_id');
if ($userId && isset($account['_id']) && $account['_id'] == $userId) {
echo $this->view('2fa:views/panel.php', compact('account'));
}
});
// overide views
$this->path('cockpit', __DIR__.'/views/cockpit');
// overide routes
$this->bind('/auth/check', function() {
if ($data = $this->param('auth')) {
$user = $this->module('cockpit')->authenticate($data);
if ($user && !$this->module('cockpit')->hasaccess('cockpit', 'backend', @$user['group'])) {
$user = null;
}
if (!$user) {
return ['success' => false];
}
if (isset($user['twofa']) && $user['twofa']) {
return [
'success' => true,
'user' => [
'_id' => $user['_id'],
'name' => $user['name'],
'user' => $user['user'],
'twofa' => true
]
];
}
unset($user['twofa_secret']);
$this->trigger('cockpit.account.login', [&$user]);
$this->module('cockpit')->setUser($user);
return ['success' => true, 'twofa' => false, 'user' => $user];
}
return false;
});
$this->bind('/auth/twofavalidate', function() {
$code = $this->param('code', null);
$user = $this->param('user', null);
if (!$code || !$user) {
return ['success' => false];
}
$user = $this->storage->findOne('cockpit/accounts', ['_id' => $user['_id']]);
if (!$user) {
return ['success' => false];
}
$tfa = new \RobThree\Auth\TwoFactorAuth($this['app.name']);
if ($tfa->verifyCode($user['twofa_secret'], $code)) {
unset($user['twofa_secret']);
$this->trigger('cockpit.account.login', [&$user]);
$this->module('cockpit')->setUser($user);
return ['success' => true, 'user' => $user];
}
return ['success' => false];
});