-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathq2a-googleauthenticator-admin.php
More file actions
75 lines (59 loc) · 2.15 KB
/
Copy pathq2a-googleauthenticator-admin.php
File metadata and controls
75 lines (59 loc) · 2.15 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
<?php
namespace CodersCommunity;
require_once __DIR__ . '/../../vendor/autoload.php';
class q2a_googleauthenticator_admin
{
public function init_queries()
{
$isActive = qa_opt('googleauthenticator_login');
$result = null;
if (1 === $isActive) {
return null;
}
$queries = [];
$columns = qa_db_read_all_values(qa_db_query_sub('describe ^users'));
if (!in_array('2fa_enabled', $columns, true)) {
$queries[] = 'ALTER TABLE ^users ADD `2fa_enabled` SMALLINT (1) DEFAULT 0';
}
if (!in_array('2fa_change_date', $columns, true)) {
$queries[] = 'ALTER TABLE ^users ADD `2fa_change_date` VARCHAR (80) DEFAULT 0';
}
if (!in_array('2fa_secret', $columns, true)) {
$queries[] =
'ALTER TABLE ^users ADD `2fa_secret` VARCHAR ( 80 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL';
}
if (!in_array('2fa_recovery_code', $columns, true)) {
$queries[] = 'ALTER TABLE ^users ADD `2fa_recovery_code` VARCHAR (11) DEFAULT 0';
}
if(count($queries)) {
$result = $queries;
}
// we're already set up
qa_opt('googleauthenticator_login', 1);
return $result;
}
public function admin_form()
{
$saved = false;
if (qa_clicked('2fa_save_button')) {
$enabled = qa_post_text('googleauthenticator_enable_plugin');
qa_opt('googleauthenticator_login', empty($enabled) ? 0 : 1);
$saved = true;
}
return [
'ok' => $saved ? qa_lang('plugin_2fa/saved_plugin_settings') : null,
'fields' => [[
'type' => 'checkbox',
'label' => qa_lang('plugin_2fa/disable_plugin'),
'value' => qa_opt('googleauthenticator_login') ? true : false,
'tags' => 'NAME="googleauthenticator_enable_plugin"'
]
],
'buttons' => [[
'label' => qa_lang('plugin_2fa/save_settings'),
'tags' => 'NAME="2fa_save_button"'
]
]
];
}
}