Newer
Older
<?php
use QUI\Utils\Security\Orthos;
/**
* Create new google authenticator key for a user
*
* @param array $titles - titles of the keys that should be deleted
* @return bool - success
*/
QUI::$Ajax->registerFunction(
'package_quiqqer_authgoogle2fa_ajax_deleteKeys',
function ($userId, $titles) {
$Users = QUI::getUsers();
$AuthUser = $Users->get((int)$userId);
$titles = Orthos::clearArray(json_decode($titles, true));
$SessionUser = QUI::getUserBySession();
// @todo Check user edit permission of session user
if ($Users->isNobodyUser($SessionUser)) {
throw new QUI\Permissions\Exception(
QUI::getLocale()->get(
'quiqqer/system',
'exception.lib.user.no.edit.rights'
)
);
}
$SessionUser->checkEditPermission();
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
try {
$secrets = json_decode($AuthUser->getAttribute('quiqqer.auth.google2fa.secrets'), true);
foreach ($titles as $title) {
if (isset($secrets[$title])) {
unset($secrets[$title]);
}
}
$AuthUser->setAttribute(
'quiqqer.auth.google2fa.secrets',
json_encode($secrets)
);
$AuthUser->save();
} catch (QUI\Auth\Google2Fa\Exception $Exception) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/authgoogle2fa',
'message.ajax.deleteKeys.error',
array(
'error' => $Exception->getMessage()
)
)
);
return false;
} catch (\Exception $Exception) {
QUI::getMessagesHandler()->addError(
QUI::getLocale()->get(
'quiqqer/authgoogle2fa',
'message.ajax.general.error'
)
);
return false;
}
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get(
'quiqqer/authgoogle2fa',
'message.ajax.deleteKeys.success'
)
);
return true;
},
array('userId', 'titles'),
'Permission::checkAdminUser'
);