/** * @param UserModel $user * @return \Application\Model\BrandModel */ public function loadByUser($user) { if (!$user instanceof UserModel) { throw new InvalidArgumentException("User must be a user model"); } return $this->loadByOrganization($user->getOrganization()); }
/** * Create user to test * * @param array $data * @return Application\Model\UserModel */ protected function _createAuthUser(array $data) { $user = new Application\Model\UserModel($data); $user->save(); self::initAuthUser($user); return $user; }
/** * according to GLOBALPORTAL-31512 monetaryDataAccess should * throw exception on users created|updated that belong to an * an End customer organization * * @param (Application\Model\UserModel) $user user to be created|updated * * @throw Application\Exceptions\InvalidArgumentException; * @author Francisco Marcos <*****@*****.**> * @return null **/ protected function _validateUserData(UserModel $user) { $data = $user->exportData(); $orgId = $data['organizationId']; $monetaryDataAccess = $data['monetaryDataAccess']; $org = $this->_orgSrv->load($orgId); if (!$org) { throw new InvalidArgumentException("Invalid parameter value: organizationId. Organitzation does not exist."); } if ($monetaryDataAccess && OrgEndUserModel::ORG_TYPE === $org->getType()) { throw new InvalidArgumentException("Invalid parameter value: monetaryinfo"); } }
/** * Returns true if and only if the assertion conditions are met * * This method is passed the ACL, Role, Resource, and privilege to which * the authorization query applies. If the $role, $resource, or $privilege * parameters are null, it means that the query applies to all Roles, * Resources, or privileges, respectively. * * @param Zend_Acl $acl * @param Zend_Acl_Role_Interface $role * @param Zend_Acl_Resource_Interface $resource * @param string $privilege * @return boolean */ public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null) { // We need specific objects to check against each other if (NULL === $role || NULL === $resource) { return false; } // Ensure we're handled User models if (!$role instanceof UserModel) { throw new \Application\Exceptions\InvalidArgumentException('Role must be an instance of UserModel'); } $orgId = null; $protectedFields = array(); $resourceClass = get_class($resource); if (!isset($this->_protectedFields[$resourceClass])) { return true; } $protectedFields = $this->_protectedFields[$resourceClass]; if ($resource instanceof OrgModelAbstract) { $originalModel = $resourceClass::find($resource->getId()); } else { if ($resource instanceof UserModel) { $originalModel = UserModel::find($resource->getId()); } else { throw new \Application\Exceptions\InvalidArgumentException('Resource must be an instance of OrgModelAbstract or UserModel'); } } return $this->_checkProtectedFields($originalModel, $resource, $protectedFields); }
public function testGeneratePassword() { $this->_user->save(); $password1 = $this->_service->generatePassword(11); $password2 = $this->_service->generatePassword(11); $password3 = $this->_service->generatePassword(); $this->assertNotEquals($password1, $password2); $this->assertEquals(11, strlen($password1)); $this->assertEquals(10, strlen($password3)); }
/** * */ public function testInsertLastUsedPasswords() { // Persist the user $this->user->save(); $passwords = array('asjfdkj2i2', 'asdjfkjasfjl', 'asdfjkasjdfas'); $result = $this->userMapper->insertLastUsedPasswords($this->user->getId(), $passwords); $this->assertNotNull($result); $this->assertEquals($passwords, $result['passwords']); return array($this->user->getId(), $passwords); }
/** * @param string $message * @param array|object $resource * @param null|string|Default_Model_User $user */ public function direct($message, $resource, $user = null) { /** @var $log Zend_Log */ $boot = $this->getFrontController()->getParam('bootstrap'); $multilog = $boot->getPluginResource('multiplelog'); $log = $multilog->getLog('audit'); // Assign username if (NULL === $user) { $ident = Zend_Auth::getInstance()->getIdentity(); $user = new UserModel(array('userName' => $ident['username'])); //Impersonation if (isset($ident['impersonation']) && isset($ident['impersonation'])) { UserService::getInstance()->generateImpersonatedUser($user, $ident['impersonation']); } } else { if (!$user instanceof UserModel) { $user = new UserModel(array('userName' => $user)); } } $log->setEventItem('username', $user->userName); if ($user->isImpersonating()) { $log->setEventItem('impersonated', "as " . $user->impersonatingOrgId . " admin"); } // Set the origin flag indicating an external API call if (!empty(\Application\Model\Mapper\OrganizationMapper::$accountingTransactionPrefix) && \Application\Model\Mapper\OrganizationMapper::$accountingTransactionPrefix == 'externalAuth') { $log->setEventItem('origin', 'external'); } else { $log->setEventItem('origin', 'portal'); } // Convert single resources to arrays if (!is_array($resource)) { $resource = array($resource); } // For each given resource log the action foreach ($resource as $res) { $log->setEventItem('resource', (string) $res); $log->audit($message); } }
public function testInvalidPassword() { $this->_user->setPassword(1243213235235); $this->assertFalse($this->_validateCollection->isValid($this->_user)); }
public function testRawFields() { $user = new UserModel(); $this->assertFalse($user->hasChanged('lastName')); $user->importData($this->_data); $this->assertTrue($user->hasChanged('lastName')); $user = new UserModel($this->_data); $this->assertFalse($user->hasChanged('lastName')); $user->setLastName('meloinvento'); $this->assertTrue($user->hasChanged('lastName')); }
/** * * @param UserModel $user * @param string $reason * @return boolean */ public function blockUser($user, $reason) { if ($user->getStatus() !== UserModel::USER_STATUS_BLOCKED) { // Block user $user->status = UserModel::USER_STATUS_BLOCKED; $user->save(); \App::audit("User " . $user->getUserName() . " has been blocked due to {$reason}", $user); \App::log()->debug("User " . $user->getUserName() . " status changed to BLOCKED"); $this->_sendEvent('update', $user); $this->_sendEvent('block', $user); return true; } return false; }