Example #1
0
    } else {
        $http->setSessionVariable('NGConnectLastAccessURI', '/');
    }
}
$ngConnectINI = eZINI::instance('ngconnect.ini');
$availableLoginMethods = $ngConnectINI->variable('ngconnect', 'LoginMethods');
$authHandlerClasses = $ngConnectINI->variable('ngconnect', 'AuthHandlerClasses');
$loginWindowType = trim($ngConnectINI->variable('ngconnect', 'LoginWindowType'));
$debugEnabled = trim($ngConnectINI->variable('ngconnect', 'DebugEnabled')) == 'true';
if (function_exists('curl_init') && function_exists('json_decode')) {
    if (in_array($loginMethod, $availableLoginMethods) && isset($authHandlerClasses[$loginMethod]) && class_exists(trim($authHandlerClasses[$loginMethod]))) {
        $authHandlerClassName = trim($authHandlerClasses[$loginMethod]);
        $authHandler = new $authHandlerClassName();
        if ($authHandler instanceof INGConnectAuthInterface) {
            $currentUser = eZUser::currentUser();
            if ($currentUser->isAnonymous() || !$currentUser->isAnonymous() && !ngConnect::userHasConnection($currentUser->ContentObjectID, $loginMethod)) {
                $result = $authHandler->getRedirectUri();
                if ($result['status'] == 'success' && isset($result['redirect_uri'])) {
                    return eZHTTPTool::redirect($result['redirect_uri']);
                } else {
                    if ($debugEnabled && isset($result['message'])) {
                        eZDebug::writeError($result['message'], 'ngconnect/login');
                    } else {
                        if ($debugEnabled) {
                            eZDebug::writeError('Unknown error', 'ngconnect/login');
                        }
                    }
                }
            }
        } else {
            if ($debugEnabled) {
Example #2
0
<?php

/** @var array $Params */
/** @var eZModule $module */
$module = $Params['Module'];
$http = eZHTTPTool::instance();
$loginMethod = $Params['LoginMethod'];
$userID = eZUser::currentUserID();
$userConnections = ngConnect::connections($userID);
foreach ($userConnections as $userConnectionObject) {
    if ($userConnectionObject->LoginMethod == $loginMethod) {
        $userConnectionObject->remove();
    }
}
if ($http->hasSessionVariable('LastAccessesURI')) {
    return $module->redirectTo($http->sessionVariable('LastAccessesURI'));
} else {
    return $module->redirectTo('/');
}
Example #3
0
         } else {
             eZUser::logoutCurrent();
         }
         redirect($http, $module);
     } else {
         $validationError = ezpI18n::tr('extension/ngconnect/ngconnect/profile', 'User with an email address supplied by your social network already exists. Try logging in instead.');
     }
 } else {
     if ($http->hasPostVariable('LoginButton') && ($ngConnectINI->variable('ProfileGenerationSettings', 'LoginUser') == 'enabled' || $forcedRedirect)) {
         // user is trying to connect to the existing account
         $login = trim($http->postVariable('Login'));
         $password = trim($http->postVariable('Password'));
         $userToLogin = eZUser::loginUser($login, $password);
         if ($userToLogin instanceof eZUser) {
             if ($userToLogin->canLoginToSiteAccess($GLOBALS['eZCurrentAccess'])) {
                 if (ngConnect::userHasConnection($userToLogin->ContentObjectID, $authResult['login_method'])) {
                     eZUser::logoutCurrent();
                     $validationError = ezpI18n::tr('extension/ngconnect/ngconnect/profile', 'This account already has a connection to selected social network.');
                 } else {
                     ngConnectFunctions::connectUser($userToLogin->ContentObjectID, $authResult['login_method'], $authResult['id']);
                     redirect($http, $module);
                 }
             } else {
                 eZUser::logoutCurrent();
                 $validationError = ezpI18n::tr('extension/ngconnect/ngconnect/profile', 'You are not allowed to access the site.');
             }
         } else {
             $validationError = ezpI18n::tr('extension/ngconnect/ngconnect/profile', 'A valid username and password is required to login.');
         }
     } else {
         if ($http->hasPostVariable('SaveButton') && !$forcedRedirect && $ngConnectINI->variable('ProfileGenerationSettings', 'CreateUser') == 'enabled') {
Example #4
0
 if (in_array($loginMethod, $availableLoginMethods) && isset($authHandlerClasses[$loginMethod]) && class_exists(trim($authHandlerClasses[$loginMethod]))) {
     $authHandlerClassName = trim($authHandlerClasses[$loginMethod]);
     $authHandler = new $authHandlerClassName();
     if ($authHandler instanceof INGConnectAuthInterface) {
         $result = $authHandler->processAuth();
         if ($result['status'] == 'success' && $result['login_method'] == $loginMethod) {
             $currentUser = eZUser::currentUser();
             if (!$currentUser->isAnonymous()) {
                 // non anonymous user is requesting connection to social network
                 // who are we to say no? connect the user and bail out
                 ngConnectFunctions::connectUser($currentUser->ContentObjectID, $result['login_method'], $result['id']);
             } else {
                 // we check if there are accounts that have a connection to social network
                 // we consider a disabled account as connected too, to allow admins to disable them and actually
                 // keep users from logging to a new account with same social network account
                 $socialNetworkConnections = ngConnect::fetchBySocialNetwork($result['login_method'], $result['id']);
                 if (is_array($socialNetworkConnections) && !empty($socialNetworkConnections)) {
                     // there are connected accounts, find them and login in
                     $usersFound = array();
                     $userIDs = array();
                     foreach ($socialNetworkConnections as $connection) {
                         $userToLogin = eZUser::fetch($connection->UserID);
                         if ($userToLogin instanceof eZUser && $userToLogin->isEnabled() && $userToLogin->canLoginToSiteAccess($GLOBALS['eZCurrentAccess'])) {
                             $usersFound[] = $userToLogin;
                             $userIDs[] = $userToLogin->ContentObjectID;
                         }
                     }
                     if (!empty($usersFound)) {
                         $usersFound[0]->loginCurrent();
                         array_shift($userIDs);
                         //TODO: Enable user to choose which account to login to
Example #5
0
 /**
  * Connects the eZ User with user from social network
  *
  * @param int $userID
  * @param string $loginMethod
  * @param int $networkUserID
  */
 public static function connectUser($userID, $loginMethod, $networkUserID)
 {
     $ngConnect = ngConnect::fetch($userID, $loginMethod, $networkUserID);
     if (!$ngConnect instanceof ngConnect) {
         $ngConnect = new ngConnect(array('user_id' => $userID, 'login_method' => $loginMethod, 'network_user_id' => $networkUserID));
         $ngConnect->store();
     }
 }
 /**
  * Returns all of a users connections to social networks
  *
  * @param int $userID
  *
  * @return array
  */
 public static function connections($userID)
 {
     return array('result' => ngConnect::connections($userID));
 }