public function __construct($options = array()) { parent::__construct($options); $this->setAttrib('id', 'signup'); // Create and configure username element: $username = $this->createElement('text', 'username', array('label' => 'model-account-username')); $username->setRequired(true)->addFilter('StringTrim')->addFilter('Alnum')->addFilter('StripTags')->addValidator('StringLength', false, array(3, 64))->setAttrib('maxlength', '64'); // First Name $firstName = $this->createElement('text', 'firstName', array('label' => 'model-account-firstName')); $firstName->setRequired(true)->addFilter('StringToLower')->addFilter('StringTrim')->addFilter('StripTags')->addFilter(new Ot_Filter_Ucwords())->setAttrib('maxlength', '64'); // Last Name $lastName = $this->createElement('text', 'lastName', array('label' => 'model-account-lastName')); $lastName->setRequired(true)->addFilter('StringTrim')->addFilter('StringToLower')->addFilter('StripTags')->addFilter(new Ot_Filter_Ucwords())->setAttrib('maxlength', '64'); // Password field $password = $this->createElement('password', 'password', array('label' => 'model-account-password')); $password->setRequired(true)->addValidator('StringLength', false, array($this->_minPasswordLength, $this->_maxPasswordLength))->addFilter('StringTrim')->addFilter('StripTags'); // Password confirmation field $passwordConf = $this->createElement('password', 'passwordConf', array('label' => 'model-account-passwordConf')); $passwordConf->setRequired(true)->addValidator('StringLength', false, array($this->_minPasswordLength, $this->_maxPasswordLength))->addValidator('Identical', false, array('token' => 'password'))->addFilter('StringTrim')->addFilter('StripTags'); // Email address field $email = $this->createElement('text', 'emailAddress', array('label' => 'model-account-emailAddress')); $email->setRequired(true)->addFilter('StringTrim')->addValidator('EmailAddress'); $timezone = $this->createElement('select', 'timezone', array('label' => 'model-account-timezone')); $timezone->addMultiOptions(Ot_Model_Timezone::getTimezoneList()); $timezone->setValue(date_default_timezone_get()); $this->addElements(array($username, $password, $passwordConf, $firstName, $lastName, $email, $timezone)); $aar = new Ot_Account_Attribute_Register(); $vars = $aar->getVars(); foreach ($vars as $v) { $elm = $v->renderFormElement(); $elm->clearDecorators(); $elm->setBelongsTo('accountAttributes'); $this->addElement($elm); } $cahr = new Ot_CustomAttribute_HostRegister(); $thisHost = $cahr->getHost('Ot_Profile'); if (is_null($thisHost)) { throw new Ot_Exception_Data('msg-error-objectNotSetup'); } $customAttributes = $thisHost->getAttributes(); foreach ($customAttributes as $a) { $elm = $a['var']->renderFormElement(); $elm->clearDecorators(); $elm->setBelongsTo('customAttributes'); $this->addElement($elm); } $this->addElement('submit', 'submit', array('buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_PRIMARY, 'label' => 'Create My Account')); $this->addElement('button', 'cancel', array('label' => 'form-button-cancel', 'type' => 'button')); $this->addDisplayGroup(array('submit', 'cancel'), 'actions', array('disableLoadDefaultDecorators' => true, 'decorators' => array('Actions'))); return $this; }
public function __construct($new = false, $me = false, $options = array()) { parent::__construct($options); $acl = Zend_Registry::get('acl'); $this->setAttrib('id', 'account'); $authAdapter = new Ot_Model_DbTable_AuthAdapter(); $adapters = $authAdapter->fetchAll(null, 'displayOrder'); // Realm Select box $realmSelect = $this->createElement('select', 'realm', array('label' => 'Login Method')); foreach ($adapters as $adapter) { $realmSelect->addMultiOption($adapter->adapterKey, $adapter->name . (!$adapter->enabled ? ' (Disabled)' : '')); } // Create and configure username element: $username = $this->createElement('text', 'username', array('label' => 'model-account-username')); $username->setRequired(true)->addFilter('StringTrim')->addFilter('Alnum')->addFilter('StripTags')->addValidator('StringLength', false, array(3, 64))->setAttrib('maxlength', '64'); // First Name $firstName = $this->createElement('text', 'firstName', array('label' => 'model-account-firstName')); $firstName->setRequired(true)->addFilter('StringToLower')->addFilter('StringTrim')->addFilter('StripTags')->addFilter(new Ot_Filter_Ucwords())->setAttrib('maxlength', '64'); // Last Name $lastName = $this->createElement('text', 'lastName', array('label' => 'model-account-lastName')); $lastName->setRequired(true)->addFilter('StringTrim')->addFilter('StringToLower')->addFilter('StripTags')->addFilter(new Ot_Filter_Ucwords())->setAttrib('maxlength', '64'); // Email address field $email = $this->createElement('text', 'emailAddress', array('label' => 'model-account-emailAddress')); $email->setRequired(true)->addFilter('StringTrim')->addValidator('EmailAddress'); $timezone = $this->createElement('select', 'timezone', array('label' => 'model-account-timezone')); $timezone->addMultiOptions(Ot_Model_Timezone::getTimezoneList()); $timezone->setValue(date_default_timezone_get()); // Role select box $roleSelect = $this->createElement('multiselect', 'role', array('label' => 'model-account-role')); $roleSelect->setRequired(true); $roleSelect->setDescription('You may select multiple roles for a user'); $roles = $acl->getAvailableRoles(); foreach ($roles as $r) { $roleSelect->addMultiOption($r['roleId'], $r['name']); } if ($new) { $this->addElements(array($realmSelect, $username, $roleSelect, $firstName, $lastName, $email, $timezone)); } else { if ($me) { $this->addElements(array($firstName, $lastName, $email, $timezone)); } else { $realmSelect->setAttrib('disabled', 'disabled'); $username->setAttrib('disabled', 'disabled'); $this->addElements(array($realmSelect, $username, $roleSelect, $firstName, $lastName, $email, $timezone)); } } $aar = new Ot_Account_Attribute_Register(); $vars = $aar->getVars(); foreach ($vars as $v) { $elm = $v->renderFormElement(); $elm->clearDecorators(); $elm->setBelongsTo('accountAttributes'); $this->addElement($elm); } $cahr = new Ot_CustomAttribute_HostRegister(); $thisHost = $cahr->getHost('Ot_Profile'); if (is_null($thisHost)) { throw new Ot_Exception_Data('msg-error-objectNotSetup'); } $customAttributes = $thisHost->getAttributes(); foreach ($customAttributes as $a) { $elm = $a['var']->renderFormElement(); $elm->clearDecorators(); $elm->setBelongsTo('customAttributes'); $this->addElement($elm); } $this->addElement('submit', 'submit', array('buttonType' => Twitter_Bootstrap_Form_Element_Submit::BUTTON_PRIMARY, 'label' => 'form-button-save')); $this->addElement('button', 'cancel', array('label' => 'form-button-cancel', 'type' => 'button')); $this->addDisplayGroup(array('submit', 'cancel'), 'actions', array('disableLoadDefaultDecorators' => true, 'decorators' => array('Actions'))); return $this; }
/** * allows a user to signup for an account * */ public function signupAction() { $realm = $this->_getParam('realm', null); if (is_null($realm)) { throw new Ot_Exception_Input('msg-error-realmNotFound'); } // Set up the auth adapter $authAdapter = new Ot_Model_DbTable_AuthAdapter(); $adapter = $authAdapter->find($realm); if (is_null($adapter)) { throw new Ot_Exception_Data($this->view->translate('ot-login-signup:realmNotFound', array('<b>' . $realm . '</b>'))); } if ($adapter->enabled == 0) { throw new Ot_Exception_Access('msg-error-authNotSupported'); } $className = (string) $adapter->class; $auth = new $className(); if (!$auth->manageLocally()) { throw new Ot_Exception_Access('msg-error-authNotSupported'); } if (!$auth->allowUserSignUp()) { throw new Ot_Exception_Access('msg-error-authNotAllowed'); } $form = new Ot_Form_Signup(); $form->removeElement('realm'); if ($this->_request->isPost()) { if ($form->isValid($_POST)) { if ($form->getValue('password') == $form->getValue('passwordConf')) { $accountData = array('username' => $form->getValue('username'), 'password' => md5($form->getValue('password')), 'realm' => $realm, 'role' => $this->_helper->configVar('newAccountRole'), 'emailAddress' => $form->getValue('emailAddress'), 'firstName' => $form->getValue('firstName'), 'lastName' => $form->getValue('lastName'), 'timezone' => $form->getValue('timezone')); $account = new Ot_Model_DbTable_Account(); if ($account->accountExists($accountData['username'], $accountData['realm'])) { $this->_helper->messenger->addError('msg-error-usernameTaken'); } else { $dba = Zend_Db_Table::getDefaultAdapter(); $dba->beginTransaction(); try { $accountData['accountId'] = $account->insert($accountData); $aar = new Ot_Account_Attribute_Register(); $vars = $aar->getVars($accountData['accountId']); $values = $form->getValues(); foreach ($vars as $varName => $var) { if (isset($values['accountAttributes'][$varName])) { $var->setValue($values['accountAttributes'][$varName]); $aar->save($var, $accountData['accountId']); } } $cahr = new Ot_CustomAttribute_HostRegister(); $thisHost = $cahr->getHost('Ot_Profile'); if (is_null($thisHost)) { throw new Ot_Exception_Data('msg-error-objectNotSetup'); } $customAttributes = $thisHost->getAttributes($accountData['accountId']); foreach ($customAttributes as $attributeName => $a) { if (array_key_exists($attributeName, $values['customAttributes'])) { $a['var']->setValue($values['customAttributes'][$attributeName]); $thisHost->saveAttribute($a['var'], $accountData['accountId'], $a['attributeId']); } } } catch (Exception $e) { $dba->rollback(); throw $e; } $dba->commit(); $loggerOptions = array('attributeName' => 'accountId', 'attributeId' => $accountData['accountId']); $this->_helper->log(Zend_Log::INFO, 'User ' . $accountData['username'] . ' created an account.', $loggerOptions); $dt = new Ot_Trigger_Dispatcher(); $dt->setVariables($accountData); $dt->password = $form->getValue('password'); $dt->loginMethod = $realm; $dt->dispatch('Login_Index_Signup'); $authAdapterModel = new Ot_Model_DbTable_AuthAdapter(); $adapter = $authAdapterModel->find($realm); $className = (string) $adapter->class; // Set up the authentication adapter $authAdapter = new $className($accountData['username'], $form->getValue('password')); $auth = Zend_Auth::getInstance(); $authRealm = new Zend_Session_Namespace('authRealm'); $authRealm->setExpirationHops(1); $authRealm->realm = $realm; $authRealm->autoLogin = $authAdapter->autoLogin(); // Attempt authentication, saving the result $result = $auth->authenticate($authAdapter); $authRealm->unsetAll(); $req = new Zend_Session_Namespace(Zend_Registry::get('siteUrl') . '_request'); $this->_helper->messenger->addSuccess('msg-info-accountCreated'); if ($result->isValid()) { $account = new Ot_Model_DbTable_Account(); $thisAccount = $account->getByUsername($accountData['username'], $realm); $auth->getStorage()->write($thisAccount); if (isset($req->uri) && $req->uri != '') { $uri = $req->uri; $req->unsetAll(); $this->_helper->redirector->gotoUrl($uri); } else { $this->_helper->redirector->gotoRoute(array(), 'default', true); } } else { $this->_helper->redirector->gotoRoute(array('realm' => $realm), 'login', true); } } } else { $this->_helper->messenger->addError('msg-error-passwordsNotMatch'); } } else { $this->_helper->messenger->addError('msg-error-invalidFormInfo'); } } $this->_helper->pageTitle('ot-login-signup:title'); $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/ot/jquery.plugin.passStrength.js'); $this->view->assign(array('realm' => $realm, 'form' => $form)); }
/** * Edits an existing user * */ public function editAction() { $req = new Zend_Session_Namespace(Zend_Registry::get('siteUrl') . '_request'); $me = Zend_Auth::getInstance()->getIdentity()->accountId == $this->_userData['accountId']; $formData = $this->_userData; if (isset($formData['accountAttributes'])) { foreach ($formData['accountAttributes'] as $key => $a) { $formData['accountAttributes'][$key] = $a->getValue(); } } if (isset($formData['customAttributes'])) { foreach ($formData['customAttributes'] as $key => $a) { $formData['customAttributes'][$key] = $a->getValue(); } } $form = new Ot_Form_Account(false, $me); $form->populate($formData); $acl = Zend_Registry::get('acl'); $resources = array(); foreach ($this->_userData['role'] as $r) { $resources[] = $acl->getResources($r); } $permissions = $this->mergeResources($resources); if ($this->_request->isPost()) { if ($form->isValid(array_merge($_POST, array('username' => $this->_userData['username'])))) { $dba = Zend_Db_Table::getDefaultAdapter(); $data = array('accountId' => $this->_userData['accountId'], 'username' => $this->_userData['username'], 'realm' => $this->_userData['realm'], 'firstName' => $form->getValue('firstName'), 'lastName' => $form->getValue('lastName'), 'emailAddress' => $form->getValue('emailAddress'), 'timezone' => $form->getValue('timezone')); if ($this->_userData['accountId'] != Zend_Auth::getInstance()->getIdentity()->accountId) { $data['role'] = $form->getValue('role'); if (!isset($data['role']) || count($data['role']) < 1) { $data['role'] = $this->_helper->configVar('defaultRole'); } } $account = new Ot_Model_DbTable_Account(); $thisAccount = $account->getByUsername($data['username'], $data['realm']); if (!is_null($thisAccount) && $thisAccount->accountId != $data['accountId']) { $this->_helper->messenger->addError('msg-error-accountTaken'); } else { $dba->beginTransaction(); try { $account->update($data, null); $aar = new Ot_Account_Attribute_Register(); $vars = $aar->getVars($this->_userData['accountId']); $values = $form->getValues(); foreach ($vars as $varName => $var) { if (isset($values['accountAttributes'][$varName])) { $var->setValue($values['accountAttributes'][$varName]); $aar->save($var, $this->_userData['accountId']); } } $cahr = new Ot_CustomAttribute_HostRegister(); $thisHost = $cahr->getHost('Ot_Profile'); if (is_null($thisHost)) { throw new Ot_Exception_Data('msg-error-objectNotSetup'); } $customAttributes = $thisHost->getAttributes($this->_userData['accountId']); foreach ($customAttributes as $attributeName => $a) { if (array_key_exists($attributeName, $values['customAttributes'])) { $a['var']->setValue($values['customAttributes'][$attributeName]); $thisHost->saveAttribute($a['var'], $this->_userData['accountId'], $a['attributeId']); } } } catch (Exception $e) { $dba->rollback(); throw $e; } $dba->commit(); $loggerOptions = array('attributeName' => 'accountId', 'attributeId' => $this->_userData['accountId']); $this->_helper->log(Zend_Log::INFO, 'Account was modified.', $loggerOptions); if (isset($req->uri) && $req->uri != '') { $uri = $req->uri; $req->unsetAll(); $this->_helper->redirector->gotoUrl($uri); } else { $this->_helper->messenger->addSuccess('msg-info-accountUpdated'); $this->_helper->redirector->gotoRoute(array('accountId' => $this->_userData['accountId']), 'account', true); } } } else { $this->_helper->messenger->addError('msg-error-invalidForm'); } } if (isset($req->uri) && $req->uri != '') { $this->_helper->messenger->addError('msg-info-requiredDataBeforeContinuing'); } if ($this->_userData['accountId'] == Zend_Auth::getInstance()->getIdentity()->accountId) { $this->_helper->messenger->addInfo('msg-info-editAccountSelf'); } $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/ot/account/add.css'); $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/ot/account/add.js'); $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/ot/jquery.tooltip.min.js'); $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/ot/account/permissionsTable.js'); $this->_helper->pageTitle('ot-account-edit:title'); $this->view->assign(array('form' => $form, 'permissions' => $permissions, 'permissionList' => Zend_Json::encode($permissions))); $this->view->acl = array('edit-permission' => $this->_helper->hasAccess('edit', 'ot_acl')); }
public function delete($where) { $inTransaction = false; //whether or not we're in a transaction prior to this $dba = $this->getAdapter(); try { $dba->beginTransaction(); } catch (Exception $e) { $inTransaction = true; } $thisAccount = $this->fetchRow($where); $accountRoles = new Ot_Model_DbTable_AccountRoles(); $apiApps = new Ot_Model_DbTable_ApiApp(); $aar = new Ot_Account_Attribute_Register(); $cahr = new Ot_CustomAttribute_HostRegister(); $thisHost = $cahr->getHost('Ot_Profile'); try { $deleteResult = parent::delete($where); $accountRoles->delete($where); $apiApps->delete($where); $aar->delete($thisAccount->accountId); $thisHost->delete($thisAccount->accountId); } catch (Exception $e) { if (!$inTransaction) { $dba->rollback(); } throw new Ot_Exception('Account delete failed.'); } if (!$inTransaction) { $dba->commit(); } return $deleteResult; }