/**
  * Add  an account
  */
 function addaccountAction()
 {
     $form_mode = $this->getRequest()->getParam("form_mode");
     $changePassword = $this->getRequest()->getParam("change_password");
     $register = $this->getRequest()->getParam("register");
     if (empty($form_mode)) {
         throw new Zmax_Exception("Invalid action request (User::addaccount)");
     }
     $user = new User();
     // @todo Probably some filtering would be appropriate
     $data = array("first_name" => $_POST['first_name'], "last_name" => $_POST['last_name'], "affiliation" => $_POST['affiliation'], "address" => $_POST['address'], "city" => $_POST['city'], "state" => $_POST['state'], "zip_code" => $_POST['zip_code'], "phone" => $_POST['phone'], "email" => $_POST['email'], "country_code" => $_POST['country_code'], "requirements" => $_POST['requirements'], "cv" => $_POST['cv'], "creation_date" => new Zend_Db_Expr('CURDATE()'));
     if ($changePassword) {
         $data["password"] = $_POST['password'];
     }
     if ($form_mode == "insert") {
         $userRow = $user->createRow();
         $currentPassword = "";
         $userRow->setFromArray($data);
         $messages = $userRow->checkInsert($this->zmax_context->texts);
     } else {
         $userRow = $this->user;
         $currentPassword = $userRow->password;
         $userRow->setFromArray($data);
         $messages = $userRow->checkUpdate($this->zmax_context->texts, $changePassword);
     }
     if (count($messages) > 0) {
         $this->view->setFile("content", "error_account.xml");
         $this->view->setBlock("content", "MESSAGE", "MESSAGES");
         foreach ($messages as $message) {
             $this->view->message = $message;
             $this->view->SUCCESS = "";
             $this->view->append("MESSAGES", "MESSAGE");
         }
         //    print_r($messages);
         $this->view->form_mode = $form_mode;
         $this->view->form_user = $userRow->form($this->view, "form_user.xml", $changePassword, $register);
     } else {
         // OK, insert or update the new user
         if ($form_mode == "insert") {
             if (!$register) {
                 $this->view->content = $this->zmax_context->texts->author->confirm_account;
             } else {
                 $this->view->content = $this->zmax_context->texts->author->confirm_registration;
             }
         } else {
             $userRow->putInView($this->view);
             $this->view->setFile("content", "confirm_update_account.xml");
             $this->view->setBlock("content", "INFO_REVIEWER");
             $this->view->setBlock("content", "INFO_ATTENDEE");
             if (!$userRow->isReviewer()) {
                 $this->view->INFO_REVIEWER = "";
             }
             if (!$userRow->isParticipant()) {
                 $this->view->INFO_PARTICIPANT = "";
             }
         }
         // Encrypt the password and save
         if ($changePassword) {
             $userRow->password = md5($userRow->password);
         } else {
             // Keep the current password
             $userRow->password = $currentPassword;
         }
         // Change the default role if this is a registration
         if ($register) {
             $userRow->setRole(User::PARTICIPANT_ROLE);
         }
         $userRow->save();
     }
     echo $this->view->render("layout");
 }
Example #2
0
 /**
  * This private function takes the authors and the answers
  * from a posted form, which replace the current paper description
  */
 private function setDependentFromArray(&$input)
 {
     // Now we must take embedded objects: abstracts
     $abstract = new AbstractClass();
     if (isset($input["abstract"])) {
         foreach ($input["abstract"] as $id => $content) {
             $this->_abstract[$id] = $abstract->createRow();
             $this->_abstract[$id]->content = htmlSpecialChars($content, ENT_NOQUOTES);
             $this->_abstract[$id]->id_section = $id;
         }
     }
     // Next, authors
     $this->_authors = array();
     $this->_contactAuthor = -1;
     $user = new User();
     // Instantiate all the authors
     if (isset($input["last_name"])) {
         $emails = $input["email"];
         $lastNames = $input["last_name"];
         $firstNames = $input["first_name"];
         $affiliations = $input["affiliation"];
         $country_code = $input["country_code"];
         if (isset($input["contact_author"])) {
             $contactAuthor = $input["contact_author"];
         } else {
             $contactAuthor = -1;
         }
         foreach ($lastNames as $i => $lastName) {
             // Since the array comes from a form with possibly left
             // blank lines, we do not consider an empty name as a mistake
             if ($lastName != "") {
                 $userRow = $user->createRow();
                 $userRow->setFilterData(true);
                 $userRow->setFromArray(array("last_name" => $lastName, "first_name" => $firstNames[$i], "affiliation" => $affiliations[$i], "country_code" => $country_code[$i], "email" => $emails[$i]));
                 $this->_authors[] = $userRow;
                 // Check the contact author
                 if ($contactAuthor == $i) {
                     $this->_contactAuthor = $i;
                     $this->emailContact = $emails[$i];
                 }
             }
         }
         // End of loop on last_name
     }
     // End of test of the existence of 'last_name'
     // Get the answers to additional questions
     $this->_answers = array();
     $paperAnswer = new PaperAnswer();
     if (isset($input['answers'])) {
         foreach ($input['answers'] as $idQuestion => $idAnswer) {
             $this->_answers[$idQuestion] = $paperAnswer->createRow();
             // Initialize the answer object. Note: the paper d is not know yet
             $this->_answers[$idQuestion]->setFromArray(array("id_question" => $idQuestion, "id_answer" => $idAnswer));
         }
     }
 }
 /**
  *
  * Manage the list of program committee members
  *
  */
 function usersAction()
 {
     $texts =& $this->zmax_context->texts;
     // Create the infos for the filter list
     if (isset($_POST['filter_roles'])) {
         $filterRoles = array_flip($_POST['filter_roles']);
     } else {
         // Show only reviewers
         $filterRoles = array_flip(array("R"));
     }
     if (isset($_POST['mail_filter'])) {
         $this->view->mail_filter = $_POST['mail_filter'];
         $mailCriteria = " email LIKE '%{$this->view->mail_filter}%' ";
     } else {
         $this->view->mail_filter = "";
         $mailCriteria = " 1 ";
     }
     if (isset($_POST['name_filter'])) {
         $this->view->name_filter = $_POST['name_filter'];
         $nameCriteria = " last_name LIKE '%{$this->view->name_filter}%' ";
     } else {
         $this->view->name_filter = "";
         $nameCriteria = " 1 ";
     }
     $this->view->filter_roles_list = Zmax_View_Phplib::checkboxField("checkbox", "filter_roles[]", Config::$Roles, $filterRoles, array());
     $filterRolesList = "";
     $connector = "";
     foreach (array_flip($filterRoles) as $role) {
         $filterRolesList .= " {$connector} roles LIKE '%{$role}%' ";
         $connector = " OR ";
     }
     $user = new User();
     $request = $this->getRequest();
     $email = $request->getParam('email');
     // Check whether an export is required
     if (isset($_REQUEST['export_action'])) {
         $exportRequired = true;
         $exportType = $_REQUEST['export_action'];
     } else {
         $exportRequired = false;
     }
     // load the template
     if (!$exportRequired) {
         $this->view->setFile("content", "users.xml");
         $this->view->setBlock("content", "post_message", " ");
     } else {
         if ($exportType == Config::EXPORT_EXCEL) {
             $this->view->setFile("content", "members_xls.xml");
             $mimeType = "text/xls";
             $exportName = "members.xls";
         } else {
             // Default: HTML
             $this->view->setFile("content", "members_html.xml");
             $mimeType = "text/plain";
             $exportName = "members.html";
         }
     }
     // After submission, insert
     if (isset($_REQUEST['id_user'])) {
         $idUser = $request->getParam("id_user");
         if (!isset($_POST['form_mode'])) {
             // The user exists. It must be modified or removed
             $instr = $request->getParam("instr");
             $userRow = $user->find($idUser)->current();
             if ($instr == "modify") {
                 // Just show the form with default values
                 $this->view->pcmember_message = "Modify user infos";
                 $this->view->form_action = $texts->form->update;
                 $this->view->form_mode = "update";
                 $userRow->putInView($this->view);
             } else {
                 if ($instr == "remove") {
                     $this->view->pcmember_message = "User {$email} has been removed";
                     $this->view->form_action = $texts->form->insert;
                     $this->view->form_mode = "insert";
                     $userRow->delete();
                     // Create a new user for insertion
                     $userRow = $user->createRow();
                     $userRow->roles = User::REVIEWER_ROLE;
                     $userRow->putInView($this->view);
                 }
             }
         } else {
             // Data comes from the form
             $form_mode = $request->getParam("form_mode");
             if ($form_mode == "insert") {
                 $userRow = $user->createRow();
             } else {
                 $userRow = $user->find($idUser)->current();
             }
             $this->view->form_action = $texts->form->update;
             $userRow->email = $_POST['email'];
             $userRow->first_name = $_POST['first_name'];
             $userRow->last_name = $_POST['last_name'];
             if (isset($_POST['topics'])) {
                 $userRow->setTopicsFromArray($_POST['topics']);
             }
             if (isset($_POST['roles'])) {
                 $userRow->setRolesFromArray($_POST['roles']);
             }
             $messages = $userRow->checkValues($this->zmax_context->texts, array("affiliation", "address", "city", "zip_code"));
             // Any error ?
             if (count($messages) > 0) {
                 $this->view->setFile("error", "error.xml");
                 $this->view->setBlock("error", "ERROR", "ERRORS");
                 foreach ($messages as $message) {
                     $this->view->message = $message;
                     $this->view->append("ERRORS", "ERROR");
                 }
                 $this->view->assign("pcmember_message", "ERRORS");
                 $this->view->form_mode = $form_mode;
             } else {
                 /* Everything is OK. Save and display the form with the user */
                 $userRow->save();
                 $this->view->assign("pcmember_message", "post_message");
             }
             // Always put the current data in the view
             $userRow->putInView($this->view);
         }
     } else {
         /* Display the form with an empty user*/
         $this->view->pcmember_message = "";
         $this->view->form_action = $texts->form->insert;
         $this->view->form_mode = "insert";
         $userRow = $user->createRow();
         $userRow->roles = User::REVIEWER_ROLE;
         $userRow->putInView($this->view);
     }
     // We are ready to instantiate the form
     $this->view->form_reviewer = $userRow->form($this->view, "form_reviewer.xml");
     $this->view->someUser = Mail::SOME_USER;
     /* Select all the members and list them.
     		 First extract the 'block' describing a line from the template */
     $this->view->setBlock("content", "MEMBER", "MEMBERS");
     $pcmembers = $user->fetchAll("{$mailCriteria} AND {$nameCriteria} AND ({$filterRolesList})", 'last_name');
     $i = 0;
     foreach ($pcmembers as $member) {
         $member->putInView($this->view);
         // Choose the CSS class
         $this->view->css_class = Config::CssCLass($i++);
         $this->view->append("MEMBERS", "MEMBER");
     }
     if ($exportRequired) {
         $this->view->assign("export", "content");
         $this->exportFile($exportName, $mimeType, $this->view->export);
         return;
     }
     // Show the view
     echo $this->view->render("layout");
 }
 public function loginAction()
 {
     require_once 'Zend/Auth/Adapter/DbTable.php';
     $request = $this->getRequest();
     $validateOnly = $request->isXmlHttpRequest();
     $userObj = new User();
     $userRow = $userObj->createRow();
     if ($validateOnly) {
         $this->setNoRenderer();
     }
     $status = ValidationContainer::instance();
     if ($request->isPost()) {
         // if a user's already logged in, send them to their account home page
         $auth = Zend_Auth::getInstance();
         if ($auth->hasIdentity()) {
             #				$this->_redirect ( 'select/select' );
         }
         $request = $this->getRequest();
         // determine the page the user was originally trying to request
         $redirect = $this->_getParam('redirect');
         //if (strlen($redirect) == 0)
         //    $redirect = $request->getServer('REQUEST_URI');
         if (strlen($redirect) == 0) {
             if ($this->hasACL('pre_service')) {
                 #					$redirect = 'select/select';
             }
         }
         // initialize errors
         $status = ValidationContainer::instance();
         // process login if request method is post
         if ($request->isPost()) {
             // fetch login details from form and validate them
             $username = $this->getSanParam('username');
             $password = $this->_getParam('password');
             if (!$status->checkRequired($this, 'username', t('Login')) or !$this->_getParam('send_email') and !$status->checkRequired($this, 'password', t('Password'))) {
                 $status->setStatusMessage(t('The system could not log you in.'));
             }
             if (!$status->hasError()) {
                 // setup the authentication adapter
                 $db = Zend_Db_Table_Abstract::getDefaultAdapter();
                 $adapter = new Zend_Auth_Adapter_DbTable($db, 'user', 'username', 'password', 'md5(?)');
                 $adapter->setIdentity($username);
                 $adapter->setCredential($password);
                 // try and authenticate the user
                 $result = $auth->authenticate($adapter);
                 if ($result->isValid()) {
                     $user = new User();
                     $userRow = $user->find($adapter->getResultRowObject()->id)->current();
                     if ($user->hasPS($userRow->id)) {
                         $redirect = $redirect ? $redirect : "select/select";
                     }
                     if ($userRow->is_blocked) {
                         $status->setStatusMessage(t('That user account has been disabled.'));
                         $auth->clearIdentity();
                     } else {
                         // create identity data and write it to session
                         $identity = $user->createAuthIdentity($userRow);
                         $auth->getStorage()->write($identity);
                         // record login attempt
                         $user->recordLogin($userRow);
                         // send user to page they originally request
                         $this->_redirect($redirect);
                     }
                 } else {
                     $auth->clearIdentity();
                     switch ($result->getCode()) {
                         case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
                             $status->setStatusMessage(t('That username or password is invalid.'));
                             break;
                         case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
                             $status->setStatusMessage(t('That username or password is invalid.'));
                             break;
                         default:
                             throw new exception('login failure');
                             break;
                     }
                 }
             }
         }
     }
     if ($validateOnly) {
         $this->sendData($status);
     } else {
         $this->view->assign('status', $status);
     }
 }
Example #5
0
 public function createUserImport($form, $sendEmail = true)
 {
     $values = $form->getValues();
     $pass = Base_PasswordGenerator::generate();
     $values['password'] = $pass['hashed'];
     if ($values['symbol'] != '') {
         /**
          * 1. odnalezenia brancha o podanym symbolu (pole "symbol") w polu profil w danych z csv.
          * 2. dopisanie do profile "id_branch", "id_user", "landing" zawsze na /contact
          * 3. dopisanie uprawnien dla usera do grupy uprawnien "logowanie"
          * 4. dopisanie uprawnien dla usera do konkretnej roli szukanej po nazwie podanej w danych z csv z userami w polu "rola".
          */
         $branchModel = new Branch();
         $branch = $branchModel->getBranchBySymbol($values['symbol']);
         if (isset($branch['id'])) {
             $valuesProfile['id_branch'] = $branch['id'];
             $valuesProfile['landing'] = '/contact';
         }
         if ($values['rola'] != '') {
             $roleModel = new Role();
             $rola = $roleModel->getRoleByName($values['rola']);
             if (isset($rola['id'])) {
                 $valuesRole['id_role'] = $rola['id'];
                 $valuesRole['id_profile'] = '';
                 // po dodaniu profilu wstawiamy jego id.
             }
         }
     }
     if (isset($values['symbol'])) {
         unset($values['symbol']);
     }
     if (isset($values['rola'])) {
         unset($values['rola']);
     }
     $user = new User();
     $row = $user->createRow($values);
     $id_user = $row->save();
     if (is_array($valuesProfile)) {
         $valuesProfile['id_user'] = $id_user;
         $profile = new Profile();
         $rowProfile = $profile->createRow($valuesProfile);
         $id_profile = $rowProfile->save();
         if (isset($id_profile) && isset($valuesRole['id_role'])) {
             $valuesRole['id_profile'] = $id_profile;
             $role = new ProfileRole();
             $rowRole = $role->createRow($valuesRole);
             $id_role = $rowRole->save();
             $valuesProfileGroup['id_profile'] = $id_profile;
             $valuesProfileGroup['id_group'] = 5;
             $profileGroup = new ProfileGroup();
             $rowProfileGroup = $profileGroup->createRow($valuesProfileGroup);
             $id_profile_group = $rowProfileGroup->save();
         }
     }
     $passwordData['id_user'] = $id_user;
     $passwordData['password'] = $pass['hashed'];
     $userPassword = new UserPassword();
     $rowPassword = $userPassword->createRow($passwordData);
     $rowPassword->save();
     /*
      if($sendEmail == true) {
      $mailer = new Logic_Mailer(Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'), $translate);
      $user_row = $user->findOne($id_user);
      $mailer->userPass($pass['clean'], $user_row);
      }
     */
 }