Esempio n. 1
0
 /**
  * Testing the loadByAttribute method.
  *
  * @since 1.0
  * @dataProvider getActiveRecordProviders
  */
 public function testLoadByAttribute($provider)
 {
     $config = ConfigProvider::getInstance();
     $config->set('db.provider.name', $provider);
     $this->person->save();
     $this->person->loadByAttribute('displayName', 'unitTestUser');
     $this->assertEquals('*****@*****.**', $this->person->get('email'), 'Testing the loadByAttribute method');
     $this->person->loadByAttribute('email', '*****@*****.**');
     $this->assertEquals('unitTestUser', $this->person->getDisplayname()->getValue(), 'Testing the loadByAttribute method');
 }
Esempio n. 2
0
 /**
  * Testing that enum options are loaded correctly from the database.
  *
  * @since 1.0
  */
 public function testLoadEnumOptions()
 {
     $this->person->loadByAttribute('displayName', 'enumunittest', true);
     $this->assertEquals('Active', $this->person->getPropObject('state')->getValue(), 'Testing that enum options are loaded correctly from the database');
 }
Esempio n. 3
0
 /**
  * Testing the saveAttribute method.
  *
  * @since 1.0
  * @dataProvider getActiveRecordProviders
  */
 public function testSaveAttribute($provider)
 {
     $config = ConfigProvider::getInstance();
     $config->set('db.provider.name', $provider);
     $this->person->save();
     $this->person->saveAttribute('displayName', 'unitTestUserNew');
     $this->assertEquals('unitTestUserNew', $this->person->getDisplayName()->getValue(), 'Testing that the value was set on the object in memory along with saving to the database');
     $person = new Person();
     try {
         $person->loadByAttribute('displayName', 'unitTestUserNew');
         $this->assertEquals('unitTestUserNew', $person->getDisplayName()->getValue(), 'Testing that the value was saved to the database');
     } catch (RecordNotFoundException $e) {
         $this->fail('Failed to load the BO that was updated with the saveAttribute method');
     }
 }
Esempio n. 4
0
 /**
  * Handle POST requests (adds $currentUser Person to the session).
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @throws Alpha\Exception\IllegalArguementException
  *
  * @since 1.0
  */
 public function doPOST($request)
 {
     self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])');
     $params = $request->getParams();
     if (!is_array($params)) {
         throw new IllegalArguementException('Bad $params [' . var_export($params, true) . '] passed to doPOST method!');
     }
     $config = ConfigProvider::getInstance();
     $body = '';
     try {
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
         }
         if (isset($params['loginBut'])) {
             // if the database has not been set up yet, accept a login from the config admin username/password
             if (!ActiveRecord::isInstalled()) {
                 if ($params['email'] == $config->get('app.install.username') && password_verify($params['password'], password_hash($config->get('app.install.password'), PASSWORD_DEFAULT, ['cost' => 12]))) {
                     self::$logger->info('Logging in [' . $params['email'] . '] at [' . date('Y-m-d H:i:s') . ']');
                     $admin = new Person();
                     $admin->set('displayName', 'Admin');
                     $admin->set('email', $params['email']);
                     $admin->set('password', password_hash($params['password'], PASSWORD_DEFAULT, ['cost' => 12]));
                     $admin->set('OID', '00000000001');
                     $sessionProvider = $config->get('session.provider.name');
                     $session = SessionProviderFactory::getInstance($sessionProvider);
                     $session->set('currentUser', $admin);
                     $response = new Response(301);
                     if ($this->getNextJob() != '') {
                         $response->redirect(FrontController::generateSecureURL('act=' . $this->getNextJob()));
                         $this->clearUnitOfWorkAttributes();
                     } else {
                         $response->redirect(FrontController::generateSecureURL('act=InstallController'));
                     }
                     return $response;
                 } else {
                     throw new ValidationException('Failed to login user ' . $params['email'] . ', the password is incorrect!');
                 }
             } else {
                 // here we are attempting to load the person from the email address
                 $this->personObject->loadByAttribute('email', $params['email'], true);
                 ActiveRecord::disconnect();
                 // checking to see if the account has been disabled
                 if (!$this->personObject->isTransient() && $this->personObject->get('state') == 'Disabled') {
                     throw new SecurityException('Failed to login user ' . $params['email'] . ', that account has been disabled!');
                 }
                 // check the password
                 return $this->doLoginAndRedirect($params['password']);
             }
             $body .= View::displayPageHead($this);
             $body .= $this->personView->displayLoginForm();
         }
         if (isset($params['resetBut'])) {
             // here we are attempting to load the person from the email address
             $this->personObject->loadByAttribute('email', $params['email']);
             ActiveRecord::disconnect();
             // generate a new random password
             $newPassword = $this->personObject->generatePassword();
             // now encrypt and save the new password, then e-mail the user
             $this->personObject->set('password', password_hash($newPassword, PASSWORD_DEFAULT, ['cost' => 12]));
             $this->personObject->save();
             $message = 'The password for your account has been reset to ' . $newPassword . ' as you requested.  You can now login to the site using your ' . 'e-mail address and this new password as before.';
             $subject = 'Password change request';
             $this->personObject->sendMail($message, $subject);
             $body .= View::displayUpdateMessage('The password for the user <strong>' . $params['email'] . '</strong> has been reset, and the new password ' . 'has been sent to that e-mail address.');
             $body .= '<a href="' . $config->get('app.url') . '">Home Page</a>';
         }
     } catch (ValidationException $e) {
         $body .= View::displayPageHead($this);
         $body .= View::displayErrorMessage($e->getMessage());
         if (isset($params['reset'])) {
             $body .= $this->personView->displayResetForm();
         } else {
             $body .= $this->personView->displayLoginForm();
         }
         self::$logger->warn($e->getMessage());
     } catch (SecurityException $e) {
         $body .= View::displayPageHead($this);
         $body .= View::displayErrorMessage($e->getMessage());
         self::$logger->warn($e->getMessage());
     } catch (RecordNotFoundException $e) {
         $body .= View::displayPageHead($this);
         $body .= View::displayErrorMessage('Failed to find the user \'' . $params['email'] . '\'');
         if (isset($params['reset'])) {
             $body .= $this->personView->displayResetForm();
         } else {
             $body .= $this->personView->displayLoginForm();
         }
         self::$logger->warn($e->getMessage());
     }
     $body .= View::displayPageFoot($this);
     self::$logger->debug('<<doPOST');
     return new Response(200, $body, array('Content-Type' => 'text/html'));
 }
Esempio n. 5
0
 /**
  * Testing that we can load dirty and new objects post commit.
  *
  * @since 1.0
  */
 public function testPostCommitLoad()
 {
     $this->person->set('email', '*****@*****.**');
     $this->controller->markDirty($this->person);
     $person = $this->createPersonObject('newuser');
     $person->set('email', '*****@*****.**');
     $this->controller->markNew($person);
     try {
         $this->controller->commit();
     } catch (FailedUnitCommitException $e) {
         $this->fail('Failed to commit the unit of work transaction for new and dirty objects');
     }
     $newPerson = new Person();
     try {
         $newPerson->loadByAttribute('email', '*****@*****.**');
     } catch (RecordNotFoundException $e) {
         $this->fail('Failed to load the new person that we commited in the unit of work');
     }
     $dirtyPerson = new Person();
     try {
         $dirtyPerson->loadByAttribute('email', '*****@*****.**');
     } catch (RecordNotFoundException $e) {
         $this->fail('Failed to load the dirty person that we commited in the unit of work');
     }
 }