public function testFindActivationTokenByUserId()
 {
     $link = new \Application\Model\UserActivationTokenModel();
     $link->setUserId($this->_userId);
     $link->setToken('token23984u2093');
     $this->userMapper->insertActivationToken($link);
     $link = $this->userMapper->findActivationToken($link->getUserId(), $link->getToken());
     $this->assertNotNull($link);
     $this->assertNotNull($link->getUserId());
 }
 public function tearDown()
 {
     parent::tearDown();
     /**
      * @var $user \Application\Model\UserModel
      */
     $user = $this->_userMapper->findOneById($this->_itemId);
     if ($user->status === \Application\Model\UserModel::USER_STATUS_DEACTIVATED) {
         $user->status = \Application\Model\UserModel::USER_STATUS_ACTIVATED;
         $user->save();
     }
 }
 /**
  * Route shutdown hook
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     // Setup Protobuf based mappers
     $ident = \Zend_Auth::getInstance()->getIdentity();
     $lang = null;
     if (!isset($ident['apiId'])) {
         $user = \Application\Model\Mapper\UserMapper::getInstance()->findOneByUserName($ident['username']);
         if ($user) {
             $lang = $user->language;
         } else {
             if (isset($ident['authType']) && $ident['authType'] !== App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC) {
                 try {
                     if (isset($ident['orgId'])) {
                         $org = \Application\Service\OrgService::getInstance()->load($ident['orgId']);
                         if ($org) {
                             $lang = $org->defaultLanguage;
                         }
                     }
                 } catch (Exception $e) {
                     \App::log()->warn("No language defined. Using english.");
                     \App::log()->warn($e);
                 }
             }
         }
     }
     self::generateToken($ident['username'], $ident['orgId'], $lang);
 }
 public function tearDown()
 {
     // Make sure we remove it from the db
     if ($user = UserMapper::getInstance()->findOneByUserName($this->_data['userName'])) {
         $user->delete();
     }
 }
 /**
  * @depends testInsertLastUsedPasswords
  */
 public function testGetLastUsedPasswords(array $data)
 {
     $userId = $data[0];
     $passwords = $data[1];
     $result = $this->userMapper->getLastUsedPasswords($userId);
     $this->assertNotEmpty($result);
     $this->assertEquals($passwords, $result);
 }
 public function tearDown()
 {
     if (isset($this->_user) && $this->_user->getId()) {
         $this->_user->delete();
     }
     if ($user = Mapper\UserMapper::getInstance()->findOneByUserName($this->_data['userName'])) {
         $user->delete();
     }
 }
 /**
  * Route shutdown hook -- Check for router exceptions
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return;
     }
     $ident = \Zend_Auth::getInstance()->getIdentity();
     if (isset($ident['authType']) && in_array($ident['authType'], array(App_Controller_Plugin_Auth::AUTH_TYPE_ASYNC, App_Controller_Plugin_Auth::AUTH_TYPE_ACTIVATION_TOKEN, App_Controller_Plugin_Auth::AUTH_TYPE_DOWNLOAD_TOKEN, App_Controller_Plugin_Auth::AUTH_TYPE_EXTERNAL, App_Controller_Plugin_Auth::AUTH_TYPE_THIRD_PARTY, App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD, App_Controller_Plugin_Auth::AUTH_TYPE_LOST_PASSWORD_TOKEN, App_Controller_Plugin_Auth::AUTH_TYPE_PASSWORD_EXPIRED_TOKEN))) {
         return;
     }
     $sessionMapper = SessionMapper::getInstance();
     $session = $sessionMapper->findOneById(\Zend_Session::getId());
     if (!$session || !isset($session['id'])) {
         return;
     }
     if (($user = UserMapper::getInstance()->findOneById($session['id'])) && isset(self::$cookieLifeTimeByOrgType[$user->getOrgType()])) {
         $cookieLifeTime = self::$cookieLifeTimeByOrgType[$user->getOrgType()];
     } else {
         $cookieLifeTime = self::$defaultCookieLifeTime;
     }
     /*
      * Old sessions use string for created/expire field. New session use a MongoDate.
      */
     $created = $session['metadata']['created'];
     if ($created instanceof \MongoDate) {
         $created = $created->sec;
     }
     if (time() - $created - $cookieLifeTime > 0) {
         $this->_forceLogout($request, "Session Expired", PermissionCodes::AUTH_SESSION_EXPIRED);
         return;
     }
     if (App_Util_Array::getItem(self::$avoidActions, $request->getModuleName() . '.' . $request->getControllerName() . '.' . $request->getActionName())) {
         return;
     }
     if ($request->getHeader('X-M2mNoRenewSession')) {
         return;
     }
     if (Zend_Session::isRegenerated()) {
         return;
     }
     if (time() - $created < (1 - self::$tolerance) * $cookieLifeTime && (!self::$useProbability || rand(0, self::$probability))) {
         return;
     }
     $sessionMapper->renewSession(\Zend_Session::getId());
     //         Zend_Session::regenerateId();
     //         if (isset($data['logout'])) {
     //             $sessionMapper->logoutSessionBySessionId(Zend_Session::getId(), $data['logout']);
     //         } else if (isset($data['messages'])) {
     //             $sessionMapper->addAllMessagesToAllSessionsBySessionId(Zend_Session::getId(), $data['messages']);
     //         }
 }
 /**
  * Validate element value
  *
  * If a translation adapter is registered, any error messages will be
  * translated according to the current locale, using the given error code;
  * if no matching translation is found, the original message will be
  * utilized.
  *
  * Note: The *filtered* value is validated.
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($data, $context = null, $removeNotPresentFields = false)
 {
     if (!$data instanceof UserModel) {
         $this->_messages = array();
         $this->_messages[self::NOT_USER] = $this->_messageTemplatesUser[self::NOT_USER];
         return false;
     }
     if (!parent::isValid($data, $context, $removeNotPresentFields)) {
         return false;
     }
     //Check if a user organization status is actived
     /**
      * @var $data \Application\Model\UserModel
      */
     $org = $data->getOrganization();
     if (!is_null($org) && $org->getStatus() === \Application\Model\OrgModelAbstract::ORG_STATUS_DEACTIVATED) {
         $this->_messages[] = "Organization disabled";
         return false;
     }
     if (null !== $data->getId()) {
         /**
          * @var $user \Application\Model\UserModel
          */
         $user = UserMapper::getInstance()->findOneById($data->getId());
         // Validate if user try to change non-editable values.
         $fields = array('userName', 'organizationId');
         if ($data->getId() === \App::getUserLogged()->getId()) {
             $fields[] = 'role';
         }
         $fixedFieldsValidator = new \App_Validate_NotEditableFields($fields);
         if (!$fixedFieldsValidator->isValid($data->exportData(), $user->exportData())) {
             $this->_messages = $fixedFieldsValidator->getMessages();
             return false;
         }
     }
     return true;
 }
/**
 * @var $watcherMapper \Core\Model\Mapper\WatcherMapper
 */
$watcherMapper = Core\Model\Mapper\WatcherMapper::getInstance();
/**
 * @var $compress \Async\Service\EventCompressor\AsyncResponseCompressorEvent
 */
$compress = new \Async\Service\EventCompressor\AsyncResponseCompressorEvent();
if (method_exists($watcherMapper, 'setTimestamps')) {
    $watcherMapper->setTimestamps(false);
}
/**
 * @var $userMapper \Application\Model\Mapper\UserMapper
 */
$userMapper = \Application\Model\Mapper\UserMapper::getInstance();
$users = $userMapper->findAll();
$userExtra = $db->user_extra->find();
/**
 * @var $user \Application\Model\UserModel
 */
foreach ($userExtra as $extra) {
    list($userId, $orgId) = explode('_', $extra['_id'], 2);
    $user = $userMapper->findOneById($userId);
    if (empty($user)) {
        continue;
    }
    \App_Test_PHPUnit_Framework_TestHelper::initAuthUser($userId);
    \Core\Model\Mapper\UserConfigMapper::getInstance()->destroySingleton();
    //Map user config
    if (isset($extra['config'])) {
示例#10
0
 protected function _mapEricssonLifeCycleModelToModel(array $data)
 {
     $lifeCycleChangeTypeMap = array(LifeCycleChangeType::MANUAL => LifeCycleModel::CHANGE_TYPE_MANUAL, LifeCycleChangeType::AUTOMATIC => LifeCycleModel::CHANGE_TYPE_AUTOMATIC);
     $data = $this->_convertFieldNamesToCammelCase($data);
     if (isset($data['state'])) {
         if (!isset($data['lifeCycleData']) || !is_array($data['lifeCycleData'])) {
             $data['lifeCycleData'] = array();
         }
         if (isset($this->_lifeCycleStatusMap[$data['state']])) {
             $data['lifeCycleData']['state'] = $this->_lifeCycleStatusMap[$data['state']];
         }
         unset($data['state']);
     }
     if (isset($data['changeType'])) {
         if (isset($lifeCycleChangeTypeMap[$data['changeType']])) {
             if (!isset($data['lifeCycleData']) || !is_array($data['lifeCycleData'])) {
                 $data['lifeCycleData'] = array();
             }
             $data['lifeCycleData']['changeType'] = $lifeCycleChangeTypeMap[$data['changeType']];
         }
         unset($data['changeType']);
     }
     if (isset($data['changeReason'])) {
         if (!isset($data['lifeCycleData']) || !is_array($data['lifeCycleData'])) {
             $data['lifeCycleData'] = array();
         }
         $data['lifeCycleData']['changeReason'] = $data['changeReason'];
         unset($data['changeReason']);
     }
     if (isset($data['currentStateDate'])) {
         if (!isset($data['lifeCycleData']) || !is_array($data['lifeCycleData'])) {
             $data['lifeCycleData'] = array();
         }
         $data['lifeCycleData']['currentStatusDate'] = $data['currentStateDate'];
         unset($data['currentStateDate']);
     }
     if (isset($data['changeUser'])) {
         if (!isset($data['lifeCycleData']) || !is_array($data['lifeCycleData'])) {
             $data['lifeCycleData'] = array();
         }
         $data['lifeCycleData']['changeUserName'] = $data['changeUser'];
         $user = UserMapper::getInstance()->findOneByUserName($data['changeUser']);
         if ($user) {
             $data['lifeCycleData']['changeUserId'] = $user->getUserName();
         } else {
             $data['lifeCycleData']['changeUserId'] = '<unknown user>';
         }
         unset($data['changeUser']);
     }
     return $data;
 }
 /**
  * Deletes model from persistent storage
  */
 public function delete()
 {
     return UserMapper::getInstance()->removeExtraData($this->getUserId(), $this->getOrgId());
 }
 /**
  * Deletes model from persistent storage.
  */
 public function delete()
 {
     $mapper = UserMapper::getInstance();
     $mapper->removeLostPasswordToken($this->getUserId(), $this->getToken());
 }
示例#13
0
 /**
  *
  * @param  type                     $userId
  * @return array
  * @throws InvalidArgumentException
  */
 public function getLastUsedPasswords($userId)
 {
     if (!$userId) {
         throw new InvalidArgumentException(get_class($this) . ": userId param not given");
     }
     $mapper = UserMapper::getInstance();
     $lastUsedPasswords = $mapper->getLastUsedPasswords($userId);
     return $lastUsedPasswords;
 }
示例#14
0
 /**
  * @param  string    $userId
  * @return UserModel
  */
 public static function find($userId)
 {
     return UserMapper::getInstance()->findOneById($userId);
 }
 /**
  * Deletes model from persistent storage.
  */
 public function delete()
 {
     $mapper = UserMapper::getInstance();
     $mapper->removeActivationToken($this->getUserId(), $this->getToken());
 }