Exemplo n.º 1
0
 /**
  * Verify a user password
  *
  * @param User $user User entity
  * @param string $password Password to be verified
  * @return bool True if password matches
  */
 public static function verifyPassword(User $user, $password)
 {
     return Bcrypt::verify(Hmac::compute(Zend_Registry::get('staticSalt'), 'sha512', $password), '$2y$14$' . $user->getPassword());
 }
Exemplo n.º 2
0
 /**
  * Update User entity
  *
  * @param User $user
  * @param array $data
  * @return void
  */
 private function _updateUser(User $user, array $data)
 {
     if (isset($data['newPassword']) && '' != $data['newPassword']) {
         // Verify old password
         #if(!UserService::verifyPassword($this->_user, $data['password'])) {
         #  throw new Exception('Current password is invalid');
         #}
         $data['password'] = UserService::encryptPassword($data['newPassword']);
     } else {
         $data['password'] = $user->getPassword();
     }
     unset($data['newPassword']);
     unset($data['newPasswordConfirm']);
     if (isset($data['role'])) {
         $data['role'] = AclRoleService::findOneById($data['role']);
     }
     if (isset($data['timeZone'])) {
         $data['timeZone'] = TimeZoneService::findOneById($data['timeZone']);
     }
     // Track changes
     $changes = array();
     foreach ($data as $key => $newValue) {
         if ($key === 'userId') {
             continue;
         }
         $oldValue = $user->{'get' . ucfirst($key)}();
         Logger::debug(__METHOD__ . ":: {$key}");
         Logger::debug(__METHOD__ . ":: OLD => " . (is_object($oldValue) ? get_class($oldValue) : var_export($oldValue, true)));
         Logger::debug(__METHOD__ . ":: NEW => " . (is_object($newValue) ? get_class($newValue) : var_export($newValue, true)));
         // Only update changed properties, and keep track of the changes as well
         if ($this->_valueChanged($oldValue, $newValue)) {
             Logger::debug(__METHOD__ . ":: {$key} has changed");
             Logger::debug(__METHOD__ . ":: OLD => " . (is_object($oldValue) ? get_class($oldValue) : var_export($oldValue, true)));
             Logger::debug(__METHOD__ . ":: NEW => " . (is_object($newValue) ? get_class($newValue) : var_export($newValue, true)));
             $oldVal = $oldValue;
             $newVal = $newValue;
             if (is_object($newValue)) {
                 if (isset($oldValue)) {
                     $oldVal = $oldValue->getName();
                 } else {
                     $oldVal = '';
                 }
                 $newVal = $newValue->getName();
             } elseif (is_object($oldValue)) {
                 $oldVal = $oldValue->getName();
             }
             $changes[] = array('item' => $key, 'oldValue' => $oldVal, 'newValue' => $newVal);
             // Set new value
             $user->{'set' . ucfirst($key)}($newValue);
         }
     }
     UserService::update();
     // Any changes to record?
     if (count($changes) > 0) {
         $description = '';
         foreach ($changes as $change) {
             $description .= sprintf('%s changed from "%s" to "%s".', $change['item'], $change['oldValue'] === 0 ? '0' : $change['oldValue'], $change['newValue']) . PHP_EOL;
         }
         UserEditEventService::create(array('user' => $user, 'editor' => $this->_user, 'ip' => $this->getRequest()->getServer('REMOTE_ADDR'), 'date' => new DateTime(), 'description' => rtrim($description)));
         return true;
     }
     return false;
 }