コード例 #1
0
ファイル: User.php プロジェクト: revolveweb/ppi-framework
 /**
  * This function cannot be called directly, it must be extended by a child class and then called.
  *
  * @return void
  */
 protected function login()
 {
     // If they are already logged in
     if ($this->isLoggedIn() !== false) {
         $this->postLoginRedirect();
     }
     // Init
     $oUser = new APP_Model_User();
     $oForm = new PPI_Model_Form();
     $oForm->init('user_login', '', 'post');
     $oForm->setFormStructure($oUser->getLoginFormStructure());
     // If they have submitted the login form
     if ($oForm->isSubmitted()) {
         $aSubmitValues = $oForm->getSubmitValues();
         // If the login fails lets set an element error
         if ($oUser->login($aSubmitValues['email'], $aSubmitValues['password']) === false) {
             $oForm->setElementError('email', 'Login Failed. Please check your credentials and try again.');
         }
         // If login was successfull, redirect to the postLoginRedirect location
         if ($oForm->isValidated()) {
             $this->postLoginRedirect();
         }
     }
     // Load our view
     $this->load('user/login', array('formBuilder' => $oForm->getRenderInformation()));
 }
コード例 #2
0
ファイル: Admin.php プロジェクト: hjr3/ppi-skeleton-app
 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()));
 }
コード例 #3
0
 /**
  * AdminController::userAddEdit()
  * Add or Edit a user
  * @return void
  */
 private function etAddEdit($p_sMode = 'create')
 {
     $oEmail = new PPI_Model_Email_Template();
     $bEdit = $p_sMode == 'edit';
     $oForm = new PPI_Model_Form();
     $checkCode = false;
     $iEmailID = $this->oInput->get($p_sMode, 0);
     $oForm->init('admin_emailtemplate_addedit');
     $oForm->setFormStructure($oEmail->getAddEditFormStructure($p_sMode));
     if ($oForm->isSubmitted() && $oForm->isValidated()) {
         $aSubmitValues = $oForm->getSubmitValues();
         // Edit mode to set the primary key so that it performs an update
         if ($bEdit && $iEmailID > 0) {
             $aSubmitValues[$oEmail->getPrimaryKey()] = $iEmailID;
         }
         // We're in add mode lets make sure this code doesn't already exist
         if (!$bEdit) {
             if (count($oEmail->getRecord('code = ' . $oEmail->quote($aSubmitValues['code']))) > 0) {
                 $oForm->setElementError('code', 'That code already exists');
             }
             // We're in edit mode, but we still need to see if they have changed the 'code'
         } else {
             // Grab the existing DB info
             if (count($aEmail = $oEmail->getRecord('id = ' . $iEmailID)) > 0) {
                 // Compare The DB info against the submitted into.
                 // If they're different then we need to make sure this doesn't exist elsewhere.
                 if ($aEmail['code'] != $aSubmitValues['code']) {
                     // Lets see if this modified code exists elsewhere.
                     if (count($aExistingEmail = $oEmail->getRecord('code = ' . $oEmail->quote($aSubmitValues['code']))) > 0) {
                         $oForm->setElementError('code', 'That code already exists');
                     }
                 }
             }
         }
         if ($oForm->isValidated()) {
             // Put the record (insert/update)
             $oEmail->putRecord($aSubmitValues);
             $this->_setFlashMessage('Email template successfully ' . ($bEdit ? 'updated' : 'created') . '.');
             $this->_redirect('admin/emailtemplate/list');
         }
     }
     if ($bEdit === true) {
         if (($iEmailID = $this->oInput->get('edit', 0)) < 1) {
             throw new PPI_Exception('Invalid Template ID: ' . $iEmailID);
         }
         // Set the defaults here
         $oForm->setDefaults($oEmail->find($iEmailID));
     }
     $aViewVars = array('bEdit' => $bEdit, 'formBuilder' => $oForm->getRenderInformation(), 'leftMenu' => true);
     $this->loadSmarty('admin/et_addedit', $aViewVars);
 }