1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-17 04:04:13 +02:00
This commit is contained in:
Ryan Cramer
2022-03-04 10:00:56 -05:00
parent f504e9b53d
commit 9912951d2b

View File

@@ -1009,20 +1009,40 @@ class ProcessLogin extends Process implements ConfigurableModule {
/** @var InputfieldRadios $f */
$f = $modules->get('InputfieldRadios');
$emailAllow = true;
$emailField = $this->fields->get($this->emailField); /** @var Field $field */
$emailAttrs = array();
$emailLabel = $this->_('Email address');
$emailNotes = array();
if($emailField && ((int) $this->allowEmail) !== 1) {
if(!$emailField->hasFlag(Field::flagUnique)) {
$emailAllow = false;
$emailNotes[] = sprintf(
$this->_('You must [enable the “unique” setting](%s) for your email field'),
$emailField->editUrl('flagUnique')
);
}
$role = $this->wire()->roles->get($this->wire()->config->superUserRolePageID);
if($this->wire()->users->count("roles=$role, email=''") > 0) {
$emailAllow = false;
$emailNotes[] = $this->_('All superusers must have an email address defined');
}
if(!$emailAllow) {
$emailAttrs['disabled'] = 'disabled';
$emailLabel .= ' - ' . $this->_('See notes below to enable');
}
}
$f->attr('name', 'allowEmail');
$f->label = $this->_('Login type');
$f->addOption(0, $this->_('User name'));
$f->addOption(1, $this->_('Email address'));
$f->addOption(2, $this->_('Either'));
$f->addOption(1, $emailLabel, $emailAttrs);
$f->addOption(2, $this->_('Either'), $emailAttrs);
$f->icon = 'sign-in';
$f->val((int) $this->allowEmail);
$emailField = $this->fields->get($this->emailField); /** @var Field $field */
if($emailField && !$emailField->hasFlag(Field::flagUnique)) {
$f->notes = sprintf(
$this->_('To use email login, you must [enable the “unique” setting](%s) for your email field.'),
$emailField->editUrl('flagUnique')
);
}
if(count($emailNotes)) $f->notes = $this->_('To use login-by-email: ') . implode(', ', $emailNotes);
$inputfields->add($f);
$inputfields->add($this->getTfaConfigInputfields());
}