コード例 #1
0
    /**
     * Logs in the user if applied username and password is
     * valid. The userID is returned if successful, false if not.
     *
     * @param array $params
     * @return bool
     */
    public static function loginUser($params = null)
    {
        $uncryptedTicket = array();

        if($params)
        {
            $uncryptedTicket["uuid"]           = $params["Username"];
            $uncryptedTicket["customerType"]   = $params["Customer_type"];
            $uncryptedTicket["userSpeciality"] = $params["User_specialty"];
            $uncryptedTicket["state"]          = $params["Province"];
            $uncryptedTicket["country"]        = $params["Country_of_registration"];
            $uncryptedTicket['toUValidated']   = isset( $params['toUValidated'] ) ? $params['toUValidated'] : true;
            $uncryptedTicket['autologin']      = isset( $params['autologin'] ) ? $params['autologin'] : false;
        }
        else
        {
            $http = eZHTTPTool::instance();

            $hashedTicket = $http->getVariable( 't' );
            if ( empty( $hashedTicket ) )
            {
                return false;
            }

            $uncryptedTicket = self::uncryptTicket ( $hashedTicket );
        }
        
        if ( !self::validateTicket($uncryptedTicket) )
        {
            return false;
        }

        $mmUser = self::createOrUpdateMMUser($uncryptedTicket);
        if( isset($uncryptedTicket['toUValidated']) )
        {
            $mmUser->toUValidated( $uncryptedTicket['toUValidated'] );
        }
        if( isset($uncryptedTicket['autologin']) )
        {
            $mmUser->isAutologin( $uncryptedTicket['autologin'] );
        }
        MMUsers::setCurrentUserObject($mmUser);

        AppBarControl::instance()->store();
        MMSelections::setCookie();
        MMUsers::setCookieUserPreferences();

        $catchUpSpe = $mmUser->getPreference( 'catchUpSpe' );
        if ( !empty( $catchUpSpe ) )
        {
            setcookie ('catchUpSpe', '1', CookieTool::getDefaultCookieExpiration(), '/', CookieTool::getCookieDomain() );
        }
        return true;
    }