<?php

/**
 * @package nxcSocialNetworks
 * @author  Serhey Dolgushev <*****@*****.**>
 * @date    16 Sep 2012
 **/
$http = eZHTTPTool::instance();
$module = $Params['Module'];
try {
    $handler = nxcSocialNetworksLoginHandler::getInstanceByType($Params['type']);
} catch (Exception $e) {
    eZDebug::writeError($e->getMessage(), 'NXC Social Networks Login');
    return $module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
if ($http->hasVariable('after_login_url')) {
    $http->setSessionVariable('AfterLoginURI', $http->variable('after_login_url'));
}
try {
    $scopes = $handler->getScopes();
    $redirectURL = $handler->getCallbackURL();
    header('Location: ' . $handler->getLoginURL($scopes, $redirectURL));
    eZExecution::cleanExit();
} catch (Exception $e) {
    eZDebug::writeError($e->getMessage(), 'NXC Social Networks Login');
    return $module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
Beispiel #2
0
 protected function __construct()
 {
     parent::__construct();
     $this->OAunth2Connection = nxcSocialNetworksOAuth2::getInstanceByType('google');
 }
try {
    $remoteID = $handler->getUserRemoteID();
} catch (Exception $e) {
    eZDebug::writeError($e->getMessage(), 'NXC Social Networks Login');
    return $module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
// Get user`s attributes
try {
    $attributes = $handler->getUserData();
} catch (Exception $e) {
    eZDebug::writeError($e->getMessage(), 'NXC Social Networks Login');
    return $module->handleError(eZError::KERNEL_NOT_FOUND, 'kernel');
}
// Trying to fetch current user from eZ Publish
$object = false;
$uniqueIdentifier = nxcSocialNetworksLoginHandler::getUniqueIdentifier();
if ($uniqueIdentifier == 'email') {
    $account = explode('|', $attributes['user_account']);
    if (isset($account[1])) {
        $user = eZUser::fetchByEmail($account[1]);
        if ($user instanceof eZUser) {
            $object = $user->attribute('contentobject');
        }
    }
} else {
    $object = eZContentObject::fetchByRemoteID($remoteID);
}
if ($object instanceof eZContentObject === false) {
    // There is no eZ publish user, so we are creating one
    $userClassID = $ini->variable('UserSettings', 'UserClassID');
    $userClass = eZContentClass::fetch($userClassID);