Skip to content

Commit

Permalink
Check if user has TOTP enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
matdave committed Dec 28, 2022
1 parent f24252b commit ce7a4aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _build/gpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"lowCaseName": "twilio",
"description": "Twilio for MODX Revolution 3.x",
"author": "John Peca",
"version": "2.0.0",
"version": "2.0.1",
"menus": [
{
"text": "twilio.users",
Expand Down
5 changes: 4 additions & 1 deletion core/components/twilio/src/Event/OnBeforeManagerPageInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ class OnBeforeManagerPageInit extends Event
{
public function run()
{
// System Wide
$enforceTotp = $this->getOption('twilio.totp_enforce', false);
// User Specific
$userTotp = $this->getOption('twilio.totp', false);
$action = $this->getOption('action');
$user = $this->modx->user;
if (!$user || $user->id === 0) {
return false;
}
if ($enforceTotp && !$_SESSION['twilio_totp_verified'] && $action !== 'totp') {
if ($enforceTotp && $userTotp && !$_SESSION['twilio_totp_verified'] && $action !== 'totp') {
$this->modx->sendRedirect(MODX_MANAGER_URL . 'index.php?a=totp&namespace=twilio');
}
}
Expand Down
5 changes: 4 additions & 1 deletion core/components/twilio/src/Event/OnManagerPageInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ class OnManagerPageInit extends Event
{
public function run()
{
// System Wide
$enforceTotp = $this->getOption('twilio.totp_enforce', false);
// User Specific
$userTotp = $this->getOption('twilio.totp', false);
$action = $this->getOption('action');
$user = $this->modx->user;
if (!$user || $user->id === 0) {
return false;
}
if ($enforceTotp && $action === 'security/profile') {
if (($enforceTotp || $userTotp) && $action === 'security/profile') {
$this->modx->regClientStartupScript($this->twilio->getOption('jsUrl') . 'mgr/twilio.js');
$profile = $user->getOne('Profile');
$extended = $profile->get('extended');
Expand Down
5 changes: 4 additions & 1 deletion core/components/twilio/src/Event/OnWebPagePrerender.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ class OnWebPagePrerender extends Event
{
public function run()
{
// System Wide
$enforceTotp = $this->getOption('twilio.totp_enforce', false);
// User Specific
$userTotp = $this->getOption('twilio.totp', false);
$totpChallenge = (int) $this->getOption('twilio.totp_challenge_page', 0);
$user = $this->modx->user;
if (!$user || $user->id === 0 || $this->modx->resource->id === $totpChallenge) {
return;
}
if ($enforceTotp && !$_SESSION['twilio_totp_verified'] && $totpChallenge > 0) {
if ($enforceTotp && $userTotp && !$_SESSION['twilio_totp_verified'] && $totpChallenge > 0) {
if ($this->modx->getOption('twilio.totp_email_on_login', null, false)) {
$this->sendEmail($user);
}
Expand Down

0 comments on commit ce7a4aa

Please sign in to comment.