public function testExportUserData() { $user = new UserModel($this->_data); $array = $user->exportData(); $this->assertTrue(is_array($array)); $this->assertEquals($this->_data, $array); }
public function testLoadUser() { // Persist user $this->_user->save(); $user = $this->_service->load($this->_user->getId()); $this->assertInstanceOf('\\Application\\Model\\UserModel', $user); $expData = $this->_user->exportData(); $actData = $user->exportData(); unset($actData['created']); unset($actData['modified']); $this->assertEquals($expData, $actData); }
/** * 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"); } }
public function generateCurrentUser(UserModel $user = null) { if (!\Zend_Auth::getInstance()->hasIdentity()) { throw new InvalidArgumentException("No logged user"); } $ident = \Zend_Auth::getInstance()->getIdentity(); if ($user instanceof CurrentUserModel) { $currentUser = $user; } else { if ($user != null) { $currentUser = new CurrentUserModel($user->exportData()); } else { $currentUser = new CurrentUserModel(); $authType = $ident['authType']; if ($authType == \App_Controller_Plugin_Auth::AUTH_TYPE_DOWNLOAD_TOKEN) { $authType = $ident['downloadToken']->authType; $currentUser->downloadToken = $ident['downloadToken']; } switch ($authType) { case \App_Controller_Plugin_Auth::AUTH_TYPE_AUTH_TOKEN: case \App_Controller_Plugin_Auth::AUTH_TYPE_REGULAR: case \App_Controller_Plugin_Auth::AUTH_TYPE_CORE: case \App_Controller_Plugin_Auth::AUTH_TYPE_ACTIVATION_TOKEN: case \App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD_TOKEN: case \App_Controller_Plugin_Auth::AUTH_TYPE_PASSWORD_EXPIRED_TOKEN: case \App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD: $user = $this->loadByUsername($ident['username']); $currentUser->importData($user->exportData()); break; case \App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL: if (!isset($ident['apiId'])) { throw new InvalidArgumentException("No apiId defined"); } $apiId = APIIdService::getInstance()->findOneByApiId($ident['apiId']); $currentUser->id = $apiId->id; $currentUser->apiId = $apiId->apiId; $currentUser->userName = '******' . $apiId->apiId; $currentUser->organizationId = $apiId->orgId; $currentUser->appId = $apiId->appId; $currentUser->monetaryDataAccess = $apiId->monetaryDataAccess; $currentUser->role = 'admin'; break; case \App_Controller_Plugin_Auth::AUTH_TYPE_THIRD_PARTY: if (!isset($ident['serviceId'])) { throw new InvalidArgumentException("No serviceId defined"); } $currentUser->id = $ident['serviceId']; $currentUser->userName = $ident['username']; $currentUser->organizationId = $ident['orgId']; $currentUser->monetaryDataAccess = $ident['monetaryDataAccess']; $currentUser->role = $ident['role']; break; case \App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC: $currentUser->id = 'ASYNC-REQUEST'; $currentUser->userName = '******'; $currentUser->organizationId = 'ASYNC-REQUEST'; break; } } } if (!empty($ident['authType'])) { $currentUser->authType = $ident['authType']; } if (!empty($ident['token'])) { $currentUser->authToken = $ident['token']; } if (!empty($ident['impersonation'])) { $this->generateImpersonatedUser($currentUser, $ident['impersonation']); } return $currentUser; }