/** * Usernames must only contain lower-case letters and numbers * * @see FieldValidation::test() */ function test(DataField $field, array &$errors = array()) { // Don't validate on get requests, we're possibly displaying and empty password field if (trim(strtolower($_SERVER['REQUEST_METHOD'])) === 'get') { return $field->value; } // Don't validate existing user names (hidden form field), it might be mixed case // on older installs and that is ok. // // NOTE: Adding a new user uses the same form as updating a user. If the username // entered matches an existing username, the existing User object is updated. if (trim(strtolower($_SERVER['REQUEST_METHOD'])) === 'post') { $user = new User(); $user->load($field->value); if ($user->isLoaded()) { return $field->value; } } if (preg_match('/^[a-z0-9]+$/', $field->value)) { return $field->value; } $errors[$field->name] = 'Username must only contain lower-case letters and numbers'; return false; }
function can($task, $extension = null, $force_reload = false) { if (!isset($this->_activeRecordHasBeenInstantiated)) { if (User::isLoaded()) { $User =& User::getCurrentUser(); return $User->can($task, $extension, $force_reload); } else { return false; } } static $Permissions; if (!isset($Permissions) || $force_reload) { $Permissions = array(); $UserPermissions =& $this->getPermissions(); foreach (array_keys($UserPermissions) as $k) { $extension_id = $UserPermissions[$k]->get('extension_id'); $Permissions[empty($extension_id) ? 'core' : $extension_id][] = $UserPermissions[$k]->get('name'); } } $extension_id = $this->_getExtensionId($extension); return !empty($Permissions[$extension_id]) && in_array($task, $Permissions[$extension_id]) ? true : $this->_addRootPermission($task, $extension_id); }
public function setUser(User $user) { if (!$user->isLoaded()) { $user->load(); } $user->resetArrayData(); $array = $user->toArray(); $this->locale = $user->locale->get(); $this->set('user', $array); $this->setTo($array['email'], $array['fullName']); $this->user = $user; }
function _valuesToForm(array &$values, User $record) { if ($record->isLoaded()) { $values['_groups'] = $this->getDi()->subusersSubscriptionTable->getForUser($record->pk()); } else { $values['_groups'] = array(); } }
function beforeSave(array &$values, User $record) { if (!empty($values['_pass'])) { $record->setPass($values['_pass']); } if (!$record->isLoaded()) { $record->is_approved = 1; } }
function init() { /* General Settings */ $fieldSet = $this->addElement('fieldset', 'general', array('id' => 'general', 'label' => ___('General'))); $loginGroup = $fieldSet->addGroup('', array('id' => 'login'))->setLabel(___('Username')); $login = $loginGroup->addElement('text', 'login', array('size' => 20)); $login->addRule('required'); $loginGroup->addRule('callback2', '-error-', array($this, 'checkUniqLogin')); $comment = $fieldSet->addTextarea("comment", array('style' => "width:90%", 'id' => 'comment'), array('label' => ___('Comment'))); if ($this->record && $this->record->pk()) { $url = Am_Controller::escape(Am_Controller::makeUrl('admin-users', 'login-as', null, array('id' => $this->record->pk()))); $loginGroup->addStatic('_login_as')->setContent(" <a href='{$url}' target='_blank'>" . ___("login as user") . "</a>"); } $pass = $fieldSet->addElement('password', '_pass', array('size' => 20, 'autocomplete' => 'off'))->setLabel(___('New Password')); //$pass0 = $gr->addElement('password', '_pass0', array('size' => 20)); //$pass0->addRule('eq', 'Password confirmation must be equal to Password', $pass); if ($this->getAttribute('_a_') == 'insert') { $pass->addRule('required'); } $nameField = $fieldSet->addGroup('', array('id' => 'name'), array('label' => ___('Name'))); $nameField->addElement('text', 'name_f', array('size' => 20)); $nameField->addElement('text', 'name_l', array('size' => 20)); $gr = $fieldSet->addGroup()->setLabel(___('E-Mail Address')); $gr->addElement('text', 'email', array('size' => 40))->addRule('required'); $gr->addRule('callback2', '-error-', array($this, 'checkUniqEmail')); $fieldSet->addElement('text', 'phone', array('size' => 20))->setLabel(___('Phone Number')); if ($this->record && $this->record->isLoaded()) { $resendText = Am_Controller::escape(___("Resend Signup E-Mail")); $sending = Am_Controller::escape(___('sending')); $sent = Am_Controller::escape(___('sent successfully')); $id = $this->record->pk(); $gr->addElement('static')->setContent(<<<CUT <input type='button' value='{$resendText}' id='resend-signup-email' /> <script type='text/javascript'> \$(function(){ \$("#resend-signup-email").click(function(){ var btn = this; var txt = btn.value; btn.value += '...({$sending})...'; \$.post(window.rootUrl + '/admin-users/resend-signup-email', {id: {$id}}, function(){ btn.value = txt + '...({$sent})'; setTimeout(function(){ btn.value = txt; }, 600); }); }); }); </script> CUT ); } $isLocked = $fieldSet->addElement('advradio', 'is_locked', array('id' => 'is_locked'))->loadOptions(array('' => 'No', '1' => '<font color=red><b>' . ___("Yes, locked") . '</b></font>', '-1' => '<i>' . ___("Disable auto-locking for this customer") . '</i>'))->setLabel(___('Is Locked')); if (Am_Di::getInstance()->config->get('manually_approve')) { $fieldSet->addElement('advcheckbox', 'is_approved', array('id' => 'is_approved'))->setLabel(___('Is Approved')); } $fieldSet->addElement('advradio', 'unsubscribed', array('id' => 'unsubscribed'))->setLabel(___("Is Unsubscribed?\nif enabled, this will\nunsubscribe the customer from:\n* messages that you send from aMember Cp, \n* autoresponder messages,\n* subscription expiration notices"))->loadOptions(array('' => ___('No'), '1' => ___('Yes, do not e-mail this customer for any reasons'))); if ($this->record->isLoaded()) { $fieldSet->addStatic('_signup_info', null, array('label' => ___('Signup Info')))->setContent(sprintf("<div>%s</div>", $this->record->added . ' / ' . $this->record->remote_addr)); } if (Am_Di::getInstance()->config->get('use_user_groups')) { $group = $this->addGroup('', array('id' => 'user_groups'))->setLabel(___('User Groups')); $groups = $group->addSelect('_groups', array('multiple' => 'multiple', 'class' => 'magicselect')); $groups->loadOptions(Am_Di::getInstance()->userGroupTable->getSelectOptions()); $group->addHtml()->setHtml(sprintf('<a href="%s" target="_blank">%s<a/>', Am_Controller::escape(REL_ROOT_URL . '/admin-user-groups'), ___("Edit Groups"))); } /* Address Info */ $this->insertAddressFields(); $this->insertAdditionalFields(); $event = new Am_Event_UserForm(Am_Event_UserForm::INIT, $this, $this->record, array()); $event->run(); }
static function currentUserHasRole($task, $extension = null, $force_reload = false) { if (User::isLoaded()) { $User = User::getCurrentUser(); return $User->hasRole($role_name, $force_reload); } return false; }