forked from whiteprojectcrixu/gesior-aac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalida_secret.php
59 lines (55 loc) · 1.37 KB
/
valida_secret.php
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
<?php
require __DIR__ . '/vendor/autoload.php';
require_once 'config/config.php';
define('INITIALIZED', true);
if (!defined('ONLY_PAGE'))
define('ONLY_PAGE', false);
include_once "system/load.init.php";
include_once "system/load.login.php";
include_once "system/load.database.php";
include_once "system/load.compat.php";
header('');
$hue = [];
/**
* @param String $msg
*/
function sendErrorMsg($msg = null)
{
$hue['status'] = "error";
if ($msg !== null) {
$hue['msg'] = $msg;
} else {
$hue['msg'] = "Somente requisições post são permitidas.";
}
echo json_encode($hue);
}
if (isset($_POST)) {
if (isset($_POST['SecretCode'])) {
$code = $_POST['SecretCode'];
$secret = $account_logged->getSecret();
$result = $tfa->verifyCode($secret, $code);
if ($result === true) {
$hue['status'] = 'success';
$_SESSION['SecretCode'] = $_POST['SecretCode'];
$account_logged->setSecretStatus(true);
$account_logged->save();
echo json_encode($hue);
} else {
sendErrorMsg('Secret Code inválido.');
}
} elseif (isset($_POST['inactivate'])) {
$status = $account_logged->getSecretStatus();
if ($status == 1) {
$hue['status'] = 'success';
$account_logged->setSecretStatus(false);
$account_logged->save();
echo json_encode($hue);
} else {
sendErrorMsg('always inactive');
}
} else {
sendErrorMsg('Dados post inválidos.');
}
} else {
sendErrorMsg();
}