public function preDispatch() { require_once 'models/table/User.php'; //add identity to view variables $auth = Zend_Auth::getInstance(); $identity = null; if ($auth->hasIdentity()) { //get ACLs and add to identity $acls = User::getACLs($auth->getIdentity()->id); $identity = $auth->getIdentity(); $identity->acls = $acls; $auth->getStorage()->write($identity); $this->view->assign('identity', $identity); } //set up localization //get country default locale, then check user settings if (isset($_COOKIE['locale']) and array_key_exists($_COOKIE['locale'], ITechTranslate::getLanguages())) { $locale = $_COOKIE['locale']; } else { $locale = $this->_countrySettings['locale']; } if (!$locale) { $locale = 'en_EN.UTF-8'; } if ($auth->hasIdentity() and $auth->getIdentity()->locale) { $locale = $auth->getIdentity()->locale; } //set up localization ITechTranslate::init($locale); // get Country-specific phrases for fields self::$_translations = Translation::getAll(); $this->view->assign('translation', self::translations()); //look for any status messages in the session and put the validation container in the view scope $statusObj = ValidationContainer::instance(); if (isset($_SESSION['status'])) { $statusObj->setStatusMessage($_SESSION['status']); unset($_SESSION['status']); } $this->view->assign('status', $statusObj); }
public function myaccountAction() { if (!$this->isLoggedIn()) { $this->doNoAccessError(); } if (!($user_id = $this->isLoggedIn())) { $this->doNoAccessError(); } if ($this->view->mode == 'edit') { $user_id = $this->getSanParam('id'); } $request = $this->getRequest(); $validateOnly = $request->isXmlHttpRequest(); if ($validateOnly) { $this->setNoRenderer(); } $user = new User(); $userRow = $user->find($user_id)->current(); if ($request->isPost()) { $status = ValidationContainer::instance(); //validate $status->checkRequired($this, 'first_name', 'First name'); $status->checkRequired($this, 'last_name', 'Last name'); $status->checkRequired($this, 'username', 'Login'); $status->checkRequired($this, 'email', 'Email'); //valid email? $validator = new Zend_Validate_EmailAddress(); if (!$validator->isValid($this->_getParam('email'))) { $status->addError('email', 'That email address does not appear to be valid.'); } if (strlen($this->_getParam('username')) < 3) { $status->addError('username', 'Usernames should be at least 3 characters in length.'); } //changing usernames? if ($this->_getParam('username') != $userRow->username) { //check unique username and email if ($uniqueArray = User::isUnique($this->getSanParam('username'))) { if (isset($uniqueArray['username'])) { $status->addError('username', 'That username is already in use. Please choose another one.'); } } } //changing email? if ($this->_getParam('email') != $userRow->email) { //check unique username and email if ($uniqueArray = User::isUnique(false, $this->getSanParam('email'))) { if (isset($uniqueArray['email'])) { $status->addError('email', 'That email address is already in use. Please choose another one.'); } } } //changing passwords? $passwordChange = false; if (strlen($this->_getParam('password')) > 0 and strlen($this->_getParam('confirm_password')) > 0) { if (strlen($this->_getParam('password')) < 6) { $status->addError('password', 'Passwords should be at least 6 characters in length.'); } if ($this->_getParam('password') != $this->_getParam('confirm_password')) { $status->addError('password', 'Password fields do not match. Please enter them again.'); } $passwordChange = true; } if ($status->hasError()) { $status->setStatusMessage('Your account information could not be saved.'); } else { $params = $this->_getAllParams(); if (!$passwordChange) { unset($params['password']); } self::fillFromArray($userRow, $params); if ($userRow->save()) { $status->setStatusMessage('Your account information was saved.'); if ($this->view->mode == 'edit') { $this->saveAclCheckboxes($user_id); } if ($passwordChange == true) { $email = $this->_getParam('email'); if (trim($email) != '') { $view = new Zend_View(); $view->setScriptPath(Globals::$BASE_PATH . '/app/views/scripts/email'); $view->assign('first_name', $this->_getParam('first_name')); $view->assign('username', $this->_getParam('username')); $view->assign('password', $this->_getParam('password')); $text = $view->render('text/password_changed.phtml'); $html = $view->render('html/password_changed.phtml'); $mail = new Zend_Mail(); $mail->setBodyText($text); $mail->setBodyHtml($html); $mail->setFrom(Settings::$EMAIL_ADDRESS, Settings::$EMAIL_NAME); $mail->addTo($this->_getParam('email'), $this->getSanParam('first_name') . " " . $this->getSanParam('last_name')); $mail->setSubject('Password Changed'); $mail->send(); } } } else { $status->setStatusMessage('Your account information could not be saved.'); } } if ($validateOnly) { $this->sendData($status); } else { $this->view->assign('status', $status); } } $userArray = $userRow->toArray(); if ($this->view->mode == 'edit') { //set acls $acls = User::getACLs($user_id); $userArray['acls'] = $acls; } $training_organizer_array = MultiOptionList::choicesList('user_to_organizer_access', 'user_id', $user_id, 'training_organizer_option', 'training_organizer_phrase', false, false); $this->viewAssignEscaped('training_organizer', $training_organizer_array); $this->viewAssignEscaped('user', $userArray); if ($this->hasACL('pre_service')) { $helper = new Helper(); $this->view->assign('showinstitutions', true); $this->view->assign('institutions', $helper->getInstitutions()); // Getting current credentials $auth = Zend_Auth::getInstance(); $identity = $auth->getIdentity(); $this->view->assign('userinstitutions', $helper->getUserInstitutions($user_id)); } else { $this->view->assign('showinstitutions', false); } }