1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-23 06:44:38 +02:00

Move Tfa config inputfields in ProcessLogin to separate methods so that the inputfields can also potentially be used by other modules.

This commit is contained in:
Ryan Cramer
2020-07-23 16:11:24 -04:00
parent 77d6c0061e
commit c6c639c0db
2 changed files with 129 additions and 98 deletions

View File

@@ -160,8 +160,8 @@ class ProcessLogin extends Process implements ConfigurableModule {
$this->set('tfaRecRoleIDs', array()); $this->set('tfaRecRoleIDs', array());
$this->set('tfaRememberDays', 90); $this->set('tfaRememberDays', 90);
$this->set('tfaRememberFingerprints', array('agentVL', 'accept', 'scheme', 'host')); $this->set('tfaRememberFingerprints', array('agentVL', 'accept', 'scheme', 'host'));
$this->set('tfaAutoEnableType', ''); $this->set('tfaAutoType', '');
$this->set('tfaAutoEnableRoleIDs', array()); $this->set('tfaAutoRoleIDs', array());
$this->set('allowEmail', false); $this->set('allowEmail', false);
$this->set('emailField', 'email'); $this->set('emailField', 'email');
$this->customMarkup['forgot-icon'] = wireIconMarkup('question-circle', 'fw'); $this->customMarkup['forgot-icon'] = wireIconMarkup('question-circle', 'fw');
@@ -946,24 +946,62 @@ class ProcessLogin extends Process implements ConfigurableModule {
); );
} }
$inputfields->add($f); $inputfields->add($f);
$inputfields->add($this->getTfaConfigInputfields());
}
/**
* Get Inputfields to configure Tfa settings
*
* @param array $data
* @return InputfieldFieldset
* @since 3.0.163
*
*/
public function getTfaConfigInputfields(array $data = array()) {
$defaults = array(
'tfaAutoType' => $this->tfaAutoType,
'tfaAutoRoleIDs' => $this->tfaAutoRoleIDs,
'tfaRecRoleIDs' => $this->tfaRecRoleIDs,
'tfaRememberDays' => $this->tfaRememberDays,
'tfaRememberFingerprints' => $this->tfaRememberFingerprints,
);
$data = array_merge($defaults, $data);
$modules = $this->wire()->modules;
$items = array();
$autos = array();
/** @var InputfieldFieldset $fieldset */ /** @var InputfieldFieldset $fieldset */
$fieldset = $modules->get('InputfieldFieldset'); $fieldset = $modules->get('InputfieldFieldset');
$fieldset->attr('id', 'tfaConfigFieldset');
$fieldset->label = $this->_('Two-factor authentication'); $fieldset->label = $this->_('Two-factor authentication');
$fieldset->icon = 'user-secret'; $fieldset->icon = 'user-secret';
$inputfields->add($fieldset); $fieldset->appendMarkup =
"<p><a target='_blank' href='https://modules.processwire.com/categories/tfa/'>" .
$this->_('Tfa modules in the ProcessWire modules directory') . ' ' .
wireIconMarkup('external-link') . "</a></p>";
$tfaModules = $modules->findByPrefix('Tfa'); $tfaModules = $modules->findByPrefix('Tfa');
if(count($tfaModules)) { if(!count($tfaModules)) {
$items = array(); $fieldset->description = $this->_('To configure this you must first install one or more Tfa modules and then return here.');
$autos = array(); $fieldset->collapsed = Inputfield::collapsedYes;
return $fieldset;
}
foreach($tfaModules as $name) { foreach($tfaModules as $name) {
$items[] = "[$name](" . $modules->getModuleEditUrl($name) . ")"; $items[] = "[$name](" . $modules->getModuleEditUrl($name) . ")";
/** @var Tfa $tfaModule */ /** @var Tfa $tfaModule */
$tfaModule = $modules->getModule($name, array('noCache' => true, 'noInit' => true)); $tfaModule = $modules->getModule($name, array('noCache' => true, 'noInit' => true));
if($tfaModule && $tfaModule->autoEnableSupported()) $autos[$name] = $modules->getModuleInfoProperty($name, 'title'); if($tfaModule && $tfaModule->autoEnableSupported()) {
$autos[$name] = $modules->getModuleInfoProperty($name, 'title');
} }
$fieldset->description = $this->_('Found the following Tfa modules:') . ' ' . implode(', ', $items); }
$fieldset->description =
$this->_('Found the following Tfa modules:') . ' ' . implode(', ', $items) . ' ' .
$this->_('(click to configure)');
if(count($autos)) { if(count($autos)) {
$forceLabel = $this->_('Force two-factor authentication'); $forceLabel = $this->_('Force two-factor authentication');
@@ -977,7 +1015,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
$f->addOption($name, "$title ($name)"); $f->addOption($name, "$title ($name)");
} }
$f->icon = 'gavel'; $f->icon = 'gavel';
$f->val($this->tfaAutoType ? $this->tfaAutoType : '0'); $f->val(!empty($data['tfaAutoType']) ? $data['tfaAutoType'] : '0');
$fieldset->add($f); $fieldset->add($f);
/** @var InputfieldCheckboxes $f */ /** @var InputfieldCheckboxes $f */
@@ -990,7 +1028,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
$f->addOption($role->id, $role->name); $f->addOption($role->id, $role->name);
} }
$f->icon = 'gavel'; $f->icon = 'gavel';
$f->attr('value', $this->get('tfaAutoRoleIDs')); $f->attr('value', $data['tfaAutoRoleIDs']);
$f->showIf = 'tfaAutoType!=0'; $f->showIf = 'tfaAutoType!=0';
$f->collapsed = Inputfield::collapsedBlank; $f->collapsed = Inputfield::collapsedBlank;
$fieldset->add($f); $fieldset->add($f);
@@ -1007,11 +1045,10 @@ class ProcessLogin extends Process implements ConfigurableModule {
if($role->name == 'guest') continue; if($role->name == 'guest') continue;
$f->addOption($role->id, $role->name); $f->addOption($role->id, $role->name);
} }
$f->attr('value', $this->get('tfaRecRoleIDs')); $f->attr('value', $data['tfaRecRoleIDs']);
$f->collapsed = Inputfield::collapsedBlank; $f->collapsed = Inputfield::collapsedBlank;
$fieldset->add($f); $fieldset->add($f);
/** @var InputfieldInteger $f */ /** @var InputfieldInteger $f */
$f = $modules->get('InputfieldInteger'); $f = $modules->get('InputfieldInteger');
$f->attr('name', 'tfaRememberDays'); $f->attr('name', 'tfaRememberDays');
@@ -1019,7 +1056,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
$f->description = $f->description =
$this->_('This presents users with a “Remember this computer?” option on the code entry screen at login.') . ' ' . $this->_('This presents users with a “Remember this computer?” option on the code entry screen at login.') . ' ' .
$this->_('Enter the number of days that a users browser/location can be remembered for, or 0 to disable.'); $this->_('Enter the number of days that a users browser/location can be remembered for, or 0 to disable.');
$f->attr('value', (int) $this->tfaRememberDays); $f->attr('value', (int) $data['tfaRememberDays']);
$f->icon = 'unlock-alt'; $f->icon = 'unlock-alt';
$fieldset->add($f); $fieldset->add($f);
@@ -1046,19 +1083,11 @@ class ProcessLogin extends Process implements ConfigurableModule {
$f->addOption($name, $label); $f->addOption($name, $label);
} }
$f->showIf = 'tfaRememberDays!=0'; $f->showIf = 'tfaRememberDays!=0';
$f->attr('value', $this->tfaRememberFingerprints); $f->attr('value', $data['tfaRememberFingerprints']);
$f->icon = 'lock'; $f->icon = 'lock';
$fieldset->add($f); $fieldset->add($f);
} else { return $fieldset;
$fieldset->description = $this->_('To configure this you must first install one or more Tfa modules and then return here.');
}
$fieldset->appendMarkup =
"<p><a target='_blank' href='https://modules.processwire.com/categories/tfa/'>" .
$this->_('Tfa modules in the ProcessWire modules directory') . ' ' .
wireIconMarkup('external-link') . "</a></p>";
} }
} }

View File

@@ -19,6 +19,8 @@
* @method string nameChangedWarning(Page $page, $namePrevious) * @method string nameChangedWarning(Page $page, $namePrevious)
* *
* @property bool|int $noAutoPublish Disable automatic publishing? * @property bool|int $noAutoPublish Disable automatic publishing?
* @property-write Template $template
* @property-write int $parent_id
* *
*/ */