コード例 #1
0
    public function login()
    {
        if ( !$this->_loginParams )
        {
            return $this->error();
        }

        $wsHelper = self::getWSHandler();
        $localizedLoginApplication = CacheApplicationTool::buildLocalizedApplicationByIdentifier( 'login' );
        $esbResult = new ESBResult();
        // Call the ESB Login webservice and populate the ESBResult object according to the ESB response

        $esbResponse = $wsHelper::call($this->_method, $this->_loginParams);
        static::populateESBResult($esbResult, $esbResponse);
        // UUMP autologin case
        if ( $this->_method == self::ESB_METHOD_READ )
            $esbResult->login = ( $esbResult->userId == $this->_input['userId'] );
        UserLog::instance()->step( 'esb' );

        $validationStatus = $esbResult->getValidationStatus();
        if ( $validationStatus == 'PV' && $localizedLoginApplication->getCustomParameter( 'RestrictPendingUsers' ) == 1 )
        {
            UserLog::instance()->esb_status('Pending')->store();
            $redirectURL = eZINI::instance( 'site.ini' )->variable( 'SiteSettings', 'PendingUserStaticPage' );
            if( SolrSafeOperatorHelper::featureIsActive( 'GoogleAnalytics' ) )
            {
                $redirectURL = $redirectURL . '#?vs=PV';
            }
            $this->response($redirectURL);
        }
        elseif ( $validationStatus == 'RP' && $localizedLoginApplication->getCustomParameter( 'RestrictRejectedUsers' ) == 1 )
        {
            UserLog::instance()->esb_status('Rejected')->store();
            $redirectURL = eZINI::instance( 'site.ini' )->variable( 'SiteSettings', 'RejectedUserStaticPage' );
            if( SolrSafeOperatorHelper::featureIsActive( 'GoogleAnalytics' ) )
            {
                $redirectURL = $redirectURL . '#?vs=RP';
            }
            $this->response($redirectURL);
        }
        elseif ( $esbResult->login )
        {
            $rememberMe = ( isset( $this->_input['rememberme'] ) && $this->_input['rememberme'] == 'on' );
            $context    = isset( $this->_input['context'] ) ? $this->_input['context'] : false;
            $username   = isset( $this->_input['LoginID'] ) ? $this->_input['LoginID'] : null;
            if ( isset( $this->_input['Username'] ) )
            {
                $username = $this->_input['Username'];
            }

            if ( !is_null( $esbResult->userName ) && $esbResult->userName != $username )
            {
                $username = $esbResult->userName;
            }

            if ( $this->_forceAutologin )
            {
                $esbResult->autologin = true;
            }

            // For compatibility with UUMP which do not need read call anymore
            if ( method_exists( get_class( $this ), "readCall" ) )
            {
                $isPopulated = static::populateESBResult( $esbResult, static::readCall( $username, $esbResult ) );

                if ( !$isPopulated )
                {
                    UserLog::instance()
                        ->uuid( $username )
                        ->esb_status( 'Error' )
                        ->msg('Read method call failed')
                        ->store();
                    // error log caught on WS stack
                    return $this->error();
                }
            }

            $this->_esbResult = $esbResult;

            $loginResult = MMUserLogin::esbLogin( $username, $esbResult, $rememberMe, $context );
        }

        if ( $loginResult )
        {
            $this->_isLoginSuccessful = true;

            UserLog::instance()
                ->uuid( $username )
                ->esb_status( 'Accepted' )
                ->store();

            $user = MMUsers::getCurrentUserObject();

            $sl = SystemLocale::fetchByClusterAndSystem( ClusterTool::clusterIdentifier(), 'esb_language' );
            $customerLanguage = !is_null( $sl ) ? $sl : eZINI::instance()->variable( 'RegionalSettings', 'ContentObjectLocale' );

            if( SolrSafeOperatorHelper::featureIsActive( 'AsynchronousAnalyticsLoginCall' ) && SolrSafeOperatorHelper::feature( 'AsynchronousAnalyticsLoginCall', 'GoogleAnalytics' ) )
            {
                $amq = new ActiveMQManager();
                $domains = eZINI::instance( 'merck.ini' )->variable( 'DomainMappingSettings', 'ClusterDomains' );
                $domain  = isset( $domains[ClusterTool::clusterIdentifier()] ) ? $domains[ClusterTool::clusterIdentifier()] : 'unidentified.univadis.com';
                $gasl = SystemLocale::fetchByClusterAndSystem( ClusterTool::clusterIdentifier(), 'ga_visitor_country' );
                $gaCountry = !is_null( $gasl ) ? $gasl : $user->attribute( 'country' );
                $gaParams = array(
                    'v'   => 1,
                    'tid' => 'UA-41415675-6',
                    'uid' => $user->attribute( 'uuid' ),
                    't'   => 'event',
                    'ec'  => 'esb',
                    'ea'  => 'login',
                    'ni'  => 1,
                    'cd1' => $user->attribute( 'uuid' ),
                    'cd2' => 'logged',
                    'cd7' => $gaCountry,
                    'dh'  => preg_replace( '#^.*?\.#', '', $domain ),
                );
                $gaParams = 'https://ssl.google-analytics.com/collect?' . http_build_query( $gaParams );
                $amq->sendMessageToQueue( 'portail.analytics.google', $gaParams );
            }

            $this->_destUrl = $loginResult['destUrl'];

            // Stringify params
            $loginResult['params'][AppBarControl::COOKIE_UNORDERED_APPLIST_KEY] = $user->getApplicationList();
            $loginResult['params'][MMUsers::COOKIE_KEY] = $user->getMMSettings();
            $cookieUserPreferences = MMUsers::getCookieUserPreferencesValues();
            foreach( $cookieUserPreferences as $key => $value )
            {
                $loginResult['params'][$key] = $value;
            }
            $strParams = json_encode( $loginResult['params'] );

            // Encrypts params
            $encryptedParams = MMUserLogin::encryptText( $strParams );
            // Redirect to PHP-ESI
            $redirectURL = "/loginActions.php?context=" . urlencode( $loginResult['destUrl'] ) . "&params=" . urlencode( $encryptedParams );

            $this->getSubsForOptin($user);

            // Branding reconsent check, done only if:
            // 1. feature ToUPPPopin enabled
            // 2. Always on WEB with this feature
            // 3. Only on mobile, whne setting showOnMobile is ON.
            if
            (
                SolrSafeOperatorHelper::featureIsActive( 'ToUPPPopin') 
                && 
                (
                    !ContextTool::instance()->isMobile()
                    ||
                    ( ContextTool::instance()->isMobile() && SolrSafeOperatorHelper::feature('ToUPPPopin','showOnMobile') )
                )
            )
            {
                $displayReconsent = $this->checkTouPPPopin( $esbResponse );
                // if we need to ask user for reconsent ($displayReconsent - taken fromESB response) we decide if we want page below if:
                // 1. On WEB and useDedicatedPage setting is ON
                // 2. On mobile and useDedicatedPageMobile setting is ON
                if (
                    $displayReconsent
                    &&
                    (
                        ( !ContextTool::instance()->isMobile() && SolrSafeOperatorHelper::feature( 'ToUPPPopin', 'useDedicatedPage' ) )
                        ||
                        ( ContextTool::instance()->isMobile() && SolrSafeOperatorHelper::feature( 'ToUPPPopin', 'useDedicatedPageMobile' ) )
                    )
                )
                {
                    CookieTool::destroyCookie( 'displayToUPPPopin' );
                    CookieTool::destroyCookie( 'displayToUPPPopin', '/', null );
                    CookieTool::setCookie( 'displayToUPPPage', 1, time() + ( 2 * 24 * 60 * 60 ) );
                    $touPpPageUrl = eZINI::instance( 'site.ini' )->variable( 'SiteSettings', 'ToUPPPageUrl' ) . "/#?tpc=" . urlencode( $loginResult['destUrl'] );
                    $redirectURL = "/loginActions.php?context=" . urlencode( $touPpPageUrl ) . "&params=" . urlencode( $encryptedParams );
                }
            }
            // Consult Popin for France | mobile check disabled - it fails on STG
            if( /*ContextTool::instance()->isMobile() && */ in_array(ClusterTool::clusterIdentifier(), array( 'cluster_france' )))
            {
                CookieTool::destroyCookie('displayConsultMobile');
                CookieTool::destroyCookie('displayConsultMobile', '/', null);
                CookieTool::setCookie('displayConsultMobile', $user->getConsult(), time() + ( 2 * 24 * 60 * 60 ));
            }
            
            $this->response( $redirectURL );
        }
        elseif ( $esbResult->errorCode === 9 )
        {
            UserLog::instance()->esb_status( 'Error' )->msg( 'Error 9' )->store();

            if ( $this->_isAutologin && isset($this->_input['context']) )
            {
                $redirectURL = urldecode($this->_input['context']);
                $this->forceRedirect($redirectURL);
            }
            else
            {
                return $this->error( 1 );
            }
        }
        elseif ( !$esbResult->registered )
        {
            $errorMsg = $esbResult->msg;
            if ( empty($errorMsg) ) $errorMsg = 'Could not log user';
            UserLog::instance()->esb_status( 'Error' )->msg( $errorMsg )->store();

            if ( $this->_isAutologin && isset($this->_input['context']) )
            {
                $redirectURL = urldecode($this->_input['context']);
                $this->forceRedirect($redirectURL);
            }

            //#45436 REDIRECT TO COMUNITY PAGE AFTER BAD LOG-IN 
            if ( isset($this->_input['context']) && preg_match('/comuniti.fr/', $this->_input['context']) )
            {
                $redirectURL = urldecode($this->_input['context']);
                $redirectURL = substr( urldecode( parse_url($redirectURL, PHP_URL_QUERY) ),2 );
                $this->forceRedirect($redirectURL);
            }
            
            if ( $esbResult->errorCode > 0 && $esbResult->errorCode != 10 )
            {
                return $this->error( $esbResult->errorCode );
            }

            return $this->error( 3 );
        }

        UserLog::instance()
            ->step( 'after_login' )
            ->msg( 'Error: Unprocessed login for input: ' . print_r( $this->_input, true ) )
            ->store();

        return $this->error();
    }