コード例 #1
0
    /**
     * Relog the user if rememberme is checked and not logged in
     * @param bool $try
     * @throws Exception
     * @return boolean
     */
    public static function relog($try = false)
    {
        $out = array('session_lifetime' => intval(eZINI::instance('merck.ini')->variable('WSMobile', 'SessionLifetime')));

        $backendUrl = eZINI::instance('merck.ini')->variable('WSMobile', 'BackEndUrl');
        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, $backendUrl.'/mobile.php');
        curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($c, CURLOPT_NOBODY, true);
        curl_setopt($c, CURLOPT_HEADER, true);
                        
        if ( eZINI::instance('merck.ini')->hasVariable('WSMobile', 'BackEndHeader') )
        {
            /* @type $headers array */
            $headersList = array();
            $headers = eZINI::instance('merck.ini')->variable('WSMobile', 'BackEndHeader');
            foreach ( $headers as $header => $value )
            {
                $headersList[] = sprintf('%s: %s', $header, $value);
            }
            curl_setopt($c, CURLOPT_HTTPHEADER, $headersList);
        }
        $headers = getallheaders();
        if( isset($headers['Cookie']) )
            curl_setopt($c, CURLOPT_COOKIE, $headers['Cookie']);

        $result = curl_exec($c);
        $errno = curl_errno($c);
        $error = curl_error($c);
        curl_close($c);
        
        $loggedOnBackend = true;
        if(    preg_match( '#^HTTP/1.1 302 Found#', $result )
               || (
                   preg_match( '#Set-Cookie: .*BSESSIONID=(?P<baksess>.*?);#m', $result, $m )
                && isset( $_COOKIE['BESSIONID'] )
                && $_COOKIE['BESSIONID'] != $m['baksess']
               )
        ){
            $loggedOnBackend = false;
        }
        
        if ( self::isLogged() && $loggedOnBackend )
        {
            return $out;
        }
        
        if ( isset($_COOKIE['remember_me']) )
        {
            $db = MMDB::instance();
            $corQuery = "SELECT r.code
            FROM bo_reference r
            JOIN bo_cluster_has_reference chr ON chr.cluster_identifier = '%s'
            WHERE r.type = 'country' AND r.id = chr.reference_id";
            $cor = $db->arrayQuery( sprintf( $corQuery, ClusterTool::clusterIdentifier() ) );
            if( count( $cor ) > 0 )
                $countryOfRegistration = $cor[0]['code'];
            else
                $countryOfRegistration = eZINI::instance('site.ini')->variable('RegionalSettings', 'CountryOfRegistration');

            $uuid = MMUserLogin::uncryptTicket($_COOKIE['remember_me']);
            $context = isset( $_REQUEST['context'] ) ? $_REQUEST['context'] : ContextTool::instance()->domain() . '/';
            $readService = ESBFactory::getUserService();
            $parameters  = $readService->getFormParameters($uuid);
            $datas       = $readService->read( $parameters, $uuid );
            $esbResult   = new ESBResult();

            $isPopulated = ServiceLoginUUMP::populateESBResult( $esbResult, $datas );
            
            if ( !$isPopulated )
            {
                // error log caught on WS stack
                return null;
            }

            $loginResult = MMUserLogin::esbLogin( $uuid, $esbResult, true, $context );
            
            if( is_null( $loginResult ))
            {
                $out['status'] = 'failed';
                $out['errorCode'] = 9; 
                $out['msg'] = 'User not found.';
                return $out;
            }
            
            $user = MMUsers::fetchByIdAndCountry($loginResult['params']['Username'], $countryOfRegistration);

            $loginResult['params']['mmSettings']       = $user->getMMSettings();
            $loginResult['params']['unorderedAppList'] = $user->getApplicationList();
            $loginResult['params']['alterboxMsgReset'] = $user->hasPreference('alterboxMsgReset') ? $user->getPreferences('alterboxMsgReset') : true;

            $logged = self::backendLog($loginResult['params']);

            if ( $logged )
            {
                return $out;
            }
        }

        if ( $try !== true )
        {
            throw new Exception('Missing "remember_me" cookie', 30);
        }

        return false;
    }
コード例 #2
0
$script->startup();
$script->initialize();

if( $options['clusterIdentifier'] && $options['countryCode'] )
{
    $updated = 0;
    $lowestRankingsPerQuizApp = array();
    $playerScoringRows = QuizPlayerScoring::fetchBy( array( 'cluster_identifier' => array( array( $options['clusterIdentifier'] ) ) ) );
    if( $playerScoringRows )
    {
        ClusterTool::setCurrentCluster( $options['clusterIdentifier'] );
        $us = FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' );
        foreach( $playerScoringRows as $playerScoring )
        {
            $user = MMUsers::fetchByIdAndCountry( $playerScoring->attribute( 'uuid' ), $options['countryCode'] );
            if( $user )
            {
                if( isset( $us[$user->attribute( 'user_speciality' )] ) && $us[$user->attribute( 'user_speciality' )]['id'] != $playerScoring->attribute( 'user_specialty' ) )
                {
                    if( !isset( $lowestRankingsPerQuizApp[$playerScoring->attribute( 'application_id' )] ) || ( isset( $lowestRankingsPerQuizApp[$playerScoring->attribute( 'application_id' )] ) && $lowestRankingsPerQuizApp[$playerScoring->attribute( 'application_id' )] < (int)$playerScoring->attribute( 'global_ranking' ) ) )
                        $lowestRankingsPerQuizApp[$playerScoring->attribute( 'application_id' )] = (int)$playerScoring->attribute( 'global_ranking' );
                    $oldUS = $playerScoring->attribute( 'user_specialty' );
                    $playerScoring->setAttribute( 'user_specialty', $us[$user->attribute( 'user_speciality' )]['id'] );
                    $playerScoring->store();
                    $updated++;
                    $cli->output( "Updated user speciality (" . $oldUS . " -> " . $us[$user->attribute( 'user_speciality' )]['id'] . ") in scoring data for user " . $playerScoring->attribute( 'uuid' ) );
                }
            }
        }
    }
コード例 #3
0
    /**
     * @param array $uncrytedTicket
     * @return MMUsers
     */
    public static function createOrUpdateMMUser( $uncrytedTicket )
    {
        $userId = $uncrytedTicket['uuid'];
        $customerType = $uncrytedTicket['customerType'];
        if ( isset($uncrytedTicket['userSpeciality']) )
        {
            $userSpeciality = $uncrytedTicket['userSpeciality'];
        }
        else
        {
            $userSpeciality = $uncrytedTicket['mainSpeciality'];
        }
        $state = $uncrytedTicket['state'];
        $country = eZIni::instance('site.ini')->variable('RegionalSettings','CountryOfRegistration');
        $language = $uncrytedTicket['language'];
        /**
         * @todo: check $language entry format and parse it if needed to get an iso code on 2 chars
         */
        $iniMapping = eZINI::instance('mercktaxonomymapping.ini');
        $taxonomyType = $iniMapping->variable( 'Taxonomy', 'SpecialtiesTaxonomyType');

        $specialtiesMappingINI = $iniMapping->variable( 'Taxonomy', 'Specialties' );
        $customerTypesMappingINI = $iniMapping->variable( 'Taxonomy', 'CustomerTypes' );

        if($taxonomyType != "transitive")
        {
            if ( isset( $customerTypesMappingINI[$customerType] ) )
            {
                $customerType = $customerTypesMappingINI[$customerType];
            }
            else
            {
                $customerType = $customerTypesMappingINI['Default'];
                self::updateDBWithEmptyValue( 'empty-CT', $userId, $country );
            }

            if ( isset( $specialtiesMappingINI[$userSpeciality] ) )
            {
                $userSpeciality = $specialtiesMappingINI[$userSpeciality];
            }
            else
            {
                $userSpeciality = $specialtiesMappingINI['Default'];
                self::updateDBWithEmptyValue( 'empty-SPE', $userId, $country );
            }
        }
        else
        {
            $customerTypesMapping = SolrSafeOperatorHelper::getCustomerTypes();
            if ( !isset( $customerTypesMapping["$customerType"] ) )
            {
                // fill with default value
                $customerType = $customerTypesMappingINI['Default'];
                self::updateDBWithEmptyValue( 'empty-CT', $userId, $country );
            }

            $specialtiesMapping = SolrSafeOperatorHelper::getUserSpecialities();
            if ( !isset( $specialtiesMapping[(string)$userSpeciality] ) )
            {
                // fill with default value
                $userSpeciality = $specialtiesMappingINI['Default'];
                self::updateDBWithEmptyValue( 'empty-SPE', $userId, $country );
            }
        }

        /** @var MMUsers $user */
        $user = MMUsers::fetchByIdAndCountry( $userId, $country );
        $isModifiedUser = false;

        if ( $user )
        {
            if ( $customerType != $user->attribute('customer_type') )
            {
                $user->setAttribute('customer_type', $customerType);
                $isModifiedUser = true;
            }
            if ( $userSpeciality !== $user->attribute('user_speciality') )
            {
                $mainSpeciality = UserSpecialityContentSpeciality::getContentSpeciality ( $userSpeciality );
                $defaultAdditionalSpecialities = MMUserLogin::getAddSpecialties($mainSpeciality);

                $user->setAttribute('user_speciality', $userSpeciality);

                // mapping main_spe additional spe
                $preferences = $user->getPreferences();
                $userAditionalSpecialities = $preferences['specialities'];
                array_shift($userAditionalSpecialities);
                $tmp = array_diff( $userAditionalSpecialities, $defaultAdditionalSpecialities );
                if( empty( $tmp ) )    // we don't modify the user spes if he has changed his selection
                {
                    $preferences["specialities"] = MMUserLogin::getAddSpecialties($mainSpeciality);
                    $user->setPreferences($preferences);
                }
                $user->setPreferences($preferences);

                // The user specialty has been modified, we need to update it for Quiz-type applications of the current cluster
                if( CacheApplicationTool::buildLocalizedApplicationByIdentifier('train-the-brain') instanceof ApplicationLocalized)
                {
                    $playerScoring = QuizPlayerScoring::fetchOneBy( array( 'application_id' => (int)$app->applicationObject->id, 'uuid' => $user->attribute( 'uuid' ) ) );
                    // Checking if the current user has scored at least once for the application
                    if( $playerScoring )
                    {
                        foreach( FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' ) as $k => $t )
                        {
                            if( ($k . "") === ($userSpeciality . "") )
                            {
                                // Updating the user specialty id in the player scoring table
                                $playerScoring->setAttribute( 'user_specialty', $t['id'] );
                                $playerScoring->store();
                            }
                        }
                        // Scheduling a ranking update
                        QuizPendingRankingUpdate::add( $playerScoring->attribute( 'global_ranking' ), $app->applicationObject->id );
                    }
                }

                $isModifiedUser = true;
            }

            if ( $country != $user->attribute('country') )
            {
                $user->setAttribute('country', $country);
                $isModifiedUser = true;
            }

            if( $language != $user->attribute( 'language' ) )
            {
                $user->setAttribute('language', $language );
                $isModifiedUser = true;
            }

            if ( $state != $user->attribute('state') )
            {
                $user->setAttribute('state', $state);
                $isModifiedUser = true;
            }

            if ( $isModifiedUser )
            {
                $user->setAttribute('date_update', time());
                $user->store();
            }

            // set gpnotebook hand shake data in preferences
            if($user->getGPNotebookHS())
            {
                SolrSafeOperatorHelper::getAndStoreGPNotebookHS();
            }
        }
        else
        {
            $mainSpeciality = UserSpecialityContentSpeciality::getContentSpeciality ( $userSpeciality );
            $insertedArray = array (
                'uuid' => $userId,
                'customer_type' => $customerType,
                'user_speciality' => $userSpeciality,
                'country' => $country,
                'language' => $language,
                'date_update' => time(),
                'state' => $state,
            );

            $user = new MMUsers ($insertedArray);
            $user->store();

            // mapping main_spe additional spe
            $preferences = $user->getPreferences();
            $preferences["specialities"] = MMUserLogin::getAddSpecialties($mainSpeciality);
            $user->setPreferences($preferences);

            $isModifiedUser = true;
        }

        if ( $isModifiedUser )
        {
            // Tag Lyris user to be reimported :
            $user->tagLyrisToProcess();
        }

        return $user;
    }
コード例 #4
0
    public function run()
    {
        $cluster = ClusterTool::clusterIdentifier();

        if ( !$cluster )
        {
            $this->debug( 'MMLyrisUserImportHandler : Used siteaccess is not a cluster, run the cronjob with a cluster siteaccess', 'Lyris' );
            return;
        }

        $db = eZDB::instance();
        /* @type $clusterMapping array */
        $clusterMapping = eZINI::instance( 'merck.ini' )->variable( 'ClusterSettings', 'CountryMapping' );

        try
        {
            $this->debug( 'MMLyrisUserImportHandler : BEGIN', 'Lyris' );

            $countries = array_keys( $clusterMapping, $cluster );

            foreach ( $countries as $currentCountryLanguage )
            {
                list( $currentCountry, $currentLanguage ) = explode( '|', $currentCountryLanguage );

                $this->debug( "MMLyrisUserImportHandler : Now treating country '$currentCountry' with language '$currentLanguage' (could be empty)", 'Lyris' );

                $userImportList = MMLyrisUserImport::fetchUnprocessedListByCountryLanguage( $currentCountry, $currentLanguage, null, false );

                foreach ( $userImportList as &$item )
                {
                    $username = trim( $item['username'] );
                    $country = trim( $item['country_registration'] );

                    $this->debug( 'Importing <' . $username . ' -- ' . $country . '>... ', 'Lyris' );
                    $db->begin();

                    $mainSpecialty = trim( $item['specialty'] );

                    $mmUser = MMUsers::fetchByIdAndCountry( $username, $country );
                    if ( empty( $mmUser ) )
                    {
                        $m = array();
                        if ( preg_match('#^216\.#', $mainSpecialty, $m) )
                        {
                            $contentSpecialty = UserSpecialityContentSpeciality::getContentSpeciality ( $mainSpecialty );
                            $specialties = MMUserLogin::getAddSpecialties( $contentSpecialty );
                        }
                        else
                            $specialties = MMUserLogin::getAddSpecialties( $mainSpecialty );

                        $applications = CountryAppsBar::fetchAppsBarApplicationIds( $item['customer_type'], $mainSpecialty, $country );
                        $customerType = $item['customer_type'];
                    }
                    else
                    {
                        $applications = $mmUser->getApplicationList();
                        $country = trim( $mmUser->attribute( 'country' ) );
                        $mainSpecialty = trim( $mmUser->userSpecialityId() );
                        $mSpe = trim( $mmUser->mainSpecialityId() );
                        $specialties = $mmUser->getSpecialities();

                        if ( ($i = array_search($mSpe, $specialties)) !== false )
                        {
                            unset($specialties[$i]);
                        }

                        $customerType = $mmUser->customerTypeId();
                    }

                    $mmUserExport = MMLyrisUserExport::fetchByUsernameAndCountry( $username, $country );

                    // Remove old entry to be sure NULL values will be set :
                    if ( !empty( $mmUserExport ) )
                    {
                        $mmUserExport->remove();
                    }
                    $mmUserExport = new MMLyrisUserExport( array(
                        'username' => $username
                    ) );
                    $mmUserExport->setAttribute( 'processed', 0 );
                    $mmUserExport->setAttribute( 'country_registration', empty( $country ) ? null : $country );
                    $mmUserExport->setAttribute( 'user_specialty', empty( $mainSpecialty ) ? null : $mainSpecialty );
                    $additionalSpecialties = trim( implode( ',', $specialties ) );
                    $mmUserExport->setAttribute( 'additional_specialties', empty( $additionalSpecialties ) ? null : $additionalSpecialties );
                    $mmUserExport->setAttribute( 'apps', $this->createXML( $applications ) );
                    $mmUserExport->setAttribute( 'customer_type', $customerType );

                    $mmUserExport->store();

                    $mmUserImport = MMLyrisUserImport::fetchByUsernameAndCountry( $username, $country );

                    if ( $mmUserImport instanceof MMLyrisUserImport )
                    {
                        $mmUserImport->setAttribute( 'processed', 1 );
                        $mmUserImport->store();
                    }
                    else
                    {
                        $this->debug( "User '$username' does not exist in '$country' !!!", 'LYRIS IMPORT ERROR', eZDebug::LEVEL_ERROR );
                    }

                    $db->commit();
                    $this->debug( '... DONE.', 'Lyris' );

                }
                $this->debug( count( $userImportList ) . ' items treated', 'MMLyrisUserImportHandler : END' );
            }
        }
        catch ( Exception $e )
        {
            $this->debug( $e, 'LYRIS IMPORT ERROR', eZDebug::LEVEL_ERROR );
            $db->rollback();
        }
    }
コード例 #5
0
        pack('H*', '812a30f760cf5d2d630799ef4bce3b4eaa404446b2db7f2a'),
        $userID,
        MCRYPT_MODE_CBC,
        $iv
    );
    $r64 = base64_encode($r);*/

    $r = addslashes(rtrim(mcrypt_decrypt(
        MCRYPT_3DES,
        pack('H*','812a30f760cf5d2d630799ef4bce3b4eaa404446b2db7f2a'),
        base64_decode( str_replace( ' ', '+', $hash ) ),
        MCRYPT_MODE_CBC,
        $iv
    ), "\0"));

    if(MMUsers::fetchByIdAndCountry(addslashes($r), $country) != null)
    {
        $notification = Notification::fetchNotify($r, $country, $type);

        if(is_null($notification))
        {
            //insert new notification
            $notification = new Notification(array(
                'uuid'      =>  $r,
                'country'   =>  $country,
                'type'      =>  $type,
                'counter'   =>  0
            ));

            $notification->store();
        }