Exemplo n.º 1
0
 /**
  * AdminController::userAddEdit()
  * Add or Edit a user
  * @return void
  */
 private function userAddEdit($p_sMode = 'create')
 {
     if (($iSchoolID = $this->oInput->get('schoolid', 0)) < 1) {
         throw new PPI_Exception('Invalid School ID: ' . $iSchoolID);
     }
     $bEdit = $p_sMode == 'edit';
     $oUser = new APP_Model_User();
     $oForm = new PPI_Model_Form();
     $oForm->init('admin_user_addedit');
     //$oForm->setTinyMCE(true);
     $oForm->setFormStructure($oUser->getAdminAddEditFormStructure($p_sMode));
     if ($oForm->isSubmitted() && $oForm->isValidated()) {
         $aSubmitValues = $oForm->getSubmitValues();
         // Setting the school ID when we insert the user
         if (!$bEdit) {
             $aSubmitValues['school_id'] = $iSchoolID;
         }
         // Edit mode to set the primary key so that it performs an update
         if ($bEdit && ($iUserID = $this->oInput->get($p_sMode)) > 0) {
             $aSubmitValues[$oUser->getPrimaryKey()] = $iUserID;
         }
         // Put the record (insert/update)
         $oUser->putRecord($aSubmitValues);
         $this->_setFlashMessage('User account successfully ' . ($bEdit ? 'updated' : 'created') . '.');
         $this->_redirect('admin/user/list/schoolid/' . $iSchoolID);
     } else {
         if ($bEdit === true) {
             if (($iUserID = $this->oInput->get('edit', 0)) < 1) {
                 throw new PPI_Exception('Invalid User ID: ' . $iUserID);
             }
             // Set the defaults here
             $oForm->setDefaults($oUser->find($iUserID));
         }
         $aViewVars = array('bEdit' => $bEdit, 'formBuilder' => $oForm->getRenderInformation(), 'leftMenu' => true);
         $this->loadSmarty('admin/user_addedit', $aViewVars);
     }
 }
Exemplo n.º 2
0
 function userUpdatePassword()
 {
     $sUsername = $this->get('updatepassword', '');
     if ($sUsername == '') {
         throw new PPI_Exception('Invalid Username');
     }
     $oUser = new APP_Model_User();
     $aUser = $oUser->getRecord('username = '******'Unable to find user information against: ' . $sUsername);
     }
     $iUserID = $aUser[$oUser->getPrimaryKey()];
     $oForm = new PPI_Model_Form();
     $oForm->init('admin_user_updatepassword', '', 'post');
     $oForm->setFormStructure($oUser->getAdminUpdatePasswordFormStructure());
     if ($oForm->isSubmitted()) {
         $aFormValues = $oForm->getSubmitValues();
         if ($aFormValues['password'] !== $aFormValues['password_confirm']) {
             $oForm->setElementError('password_confirm', 'Both passwords must match');
         }
         if ($oForm->isValidated()) {
             $oUser->updatePassword($iUserID, $aFormValues['password']);
             $this->redirect('admin/user');
         }
     }
     $this->adminLoad('admin/user_updatepassword', array('formBuilder' => $oForm->getRenderInformation()));
 }
Exemplo n.º 3
0
 /**
  * Send the password recovery email to the user.
  * @param string $p_sEmail The Email Address
  * @param string $p_sSubject The Subject
  * @param string $p_sMessage The Message
  * @return boolean
  */
 function sendRecoverEmail($p_aUser, $p_sSubject = '', $p_sMessage = '')
 {
     $oConfig = $this->getConfig();
     if ($p_sSubject === '') {
         $p_sSubject = 'Password recovery';
     }
     $sRecoveryCode = base64_encode(time());
     if ($p_sMessage === '') {
         $p_sMessage = "Hi, {$p_aUser['first_name']}\n\nYou have requested a password recovery and your password has now been reset.\nPlease click the following verification link to reset your password.\n";
         $p_sMessage .= $oConfig->system->base_url . 'user/recover/' . urlencode($sRecoveryCode);
     }
     $oEmail = new PPI_Model_Email_Advanced();
     $oEmail->Subject = $p_sSubject;
     $oEmail->SetFrom($oConfig->system->adminEmail, $oConfig->system->adminName);
     $oEmail->AddAddress($p_aUser['email']);
     $oEmail->AltBody = $p_sMessage;
     $oEmail->MsgHTML($p_sMessage);
     // If the email sent successfully,
     if ($oEmail->Send()) {
         $oUser = new APP_Model_User();
         $sPrimaryKey = $oUser->getPrimaryKey();
         // Lets update the users record with their recovery_code
         $oUser->putRecord(array('recovery_code' => $sRecoveryCode, $sPrimaryKey => $p_aUser[$sPrimaryKey]));
         return true;
     }
     return false;
 }