소스 검색

Remove fb externa_login replaced with HWIOAuthBundle

jmontoyaa 8 년 전
부모
커밋
1e99567bab
3개의 변경된 파일0개의 추가작업 그리고 468개의 파일을 삭제
  1. 0 217
      main/auth/external_login/facebook.inc.php
  2. 0 26
      main/auth/external_login/facebook.init.php
  3. 0 225
      main/auth/external_login/functions.inc.php

+ 0 - 217
main/auth/external_login/facebook.inc.php

@@ -1,217 +0,0 @@
-<?php
-/**
- * Licence: GPL
- * Please contact CBlue regarding any licences issues.
- * Author: noel@cblue.be
- *  Copyright: CBlue SPRL, 20XX
- *
- * External login module : FACEBOOK
- *
- * This files provides the facebookConnect()  and facebook_get_url functions
- * Please edit the facebook.conf.php file to adapt it to your fb application parameter
- */
-
-require_once dirname(__FILE__) . '/../../inc/global.inc.php';
-require_once dirname(__FILE__) . '/facebook.init.php';
-
-require_once dirname(__FILE__) . '/functions.inc.php';
-
-/**
- * This function connect to facebook and retrieves the user info
- * If user does not exist in chamilo, it creates it and logs in
- * If user already exists, it updates his info
- */
-function facebookConnect()
-{
-    $fb = new \Facebook\Facebook([
-        'app_id' => $GLOBALS['facebook_config']['appId'],
-        'app_secret' => $GLOBALS['facebook_config']['secret'],
-        'default_graph_version' => 'v2.2'
-    ]);
-
-    $helper = $fb->getRedirectLoginHelper();
-
-    try {
-        $accessToken = $helper->getAccessToken();
-    } catch(Facebook\Exceptions\FacebookResponseException $e) {
-        Display::addFlash(
-            Display::return_message('Facebook Graph returned an error: ' . $e->getMessage(), 'error')
-        );
-
-        header('Location: ' . api_get_path(WEB_PATH));
-        exit;
-    } catch(Facebook\Exceptions\FacebookSDKException $e) {
-        Display::addFlash(
-            Display::return_message('Facebook SDK returned an error: ' . $e->getMessage(), 'error')
-        );
-
-        header('Location: ' . api_get_path(WEB_PATH));
-        exit;
-    }
-
-    if (!isset($accessToken)) {
-        if (!$helper->getError()) {
-            return;
-        }
-
-        if (isset($_GET['loginFailed'])) {
-            return;
-        }
-
-        $error = implode('<br>', [
-            'Error: ' . $helper->getError(),
-            'Error Code: ' . $helper->getErrorCode(),
-            'Error Reason: ' . $helper->getErrorReason(),
-            'Error Description: ' . $helper->getErrorDescription()
-        ]);
-
-        Display::addFlash(
-            Display::return_message($error, 'error', false)
-        );
-
-        header('Location: ' . api_get_path(WEB_PATH));
-        exit;
-    }
-
-    $oAuth2Client = $fb->getOAuth2Client();
-    $tokenMetadata = $oAuth2Client->debugToken($accessToken);
-    $tokenMetadata->validateAppId($GLOBALS['facebook_config']['appId']);
-    $tokenMetadata->validateExpiration();
-
-    if (!$accessToken->isLongLived()) {
-        try {
-            $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
-        } catch (Facebook\Exceptions\FacebookSDKException $e) {
-            Display::addFlash(
-                Display::return_message('Error getting long-lived access token: ' . $e->getMessage(), 'error')
-            );
-
-            header('Location: ' . api_get_path(WEB_PATH));
-            exit;
-        }
-    }
-
-    try {
-        $response = $fb->get('/me?fields=id,first_name,last_name,locale,email', $accessToken->getValue());
-    } catch(Facebook\Exceptions\FacebookResponseException $e) {
-        Display::addFlash(
-            Display::return_message('Graph returned an error: ' . $e->getMessage(), 'error')
-        );
-
-        header('Location: ' . api_get_path(WEB_PATH));
-        exit;
-    } catch(Facebook\Exceptions\FacebookSDKException $e) {
-        Display::addFlash(
-            Display::return_message('Facebook SDK returned an error: ' . $e->getMessage(), 'error')
-        );
-
-        header('Location: ' . api_get_path(WEB_PATH));
-        exit;
-    }
-
-    $user = $response->getGraphUser();
-    $language = facebookPluginGetLanguage($user['locale']);
-
-    if (!$language) {
-        $language = 'en_US';
-    }
-
-    $u = [
-        'firstname' => $user->getFirstName(),
-        'lastname' => $user->getLastName(),
-        'status' => STUDENT,
-        'email' => $user->getEmail(),
-        'username' => changeToValidChamiloLogin($user->getEmail()),
-        'language' => $language,
-        'password' => 'facebook',
-        'auth_source' => 'facebook',
-        'extra' => array()
-    ];
-    $chamiloUinfo = api_get_user_info_from_email($user->getEmail());
-
-    $_user['uidReset'] = true;
-    $_user['language'] = $language;
-
-    if ($chamiloUinfo === false) {
-        // We have to create the user
-        $chamilo_uid = external_add_user($u);
-
-        if ($chamilo_uid === false) {
-            Display::addFlash(
-                Display::return_message(get_lang('UserNotRegistered'), 'error')
-            );
-
-            header('Location: ' . api_get_path(WEB_PATH));
-            exit;
-        }
-
-        $_user['user_id'] = $chamilo_uid;
-        $_SESSION['_user'] = $_user;
-
-        header('Location: ' . api_get_path(WEB_PATH));
-        exit();
-    }
-
-    // User already exists, update info and login
-    $chamilo_uid = $chamiloUinfo['user_id'];
-    $u['user_id'] = $chamilo_uid;
-    external_update_user($u);
-    $_user['user_id'] = $chamilo_uid;
-    $_SESSION['_user'] = $_user;
-
-    header('Location: ' . api_get_path(WEB_PATH));
-    exit();
-}
-
-/**
- * Get facebook login url for the platform
- * @return string
- */
-function facebookGetLoginUrl()
-{
-    $fb = new \Facebook\Facebook([
-        'app_id' => $GLOBALS['facebook_config']['appId'],
-        'app_secret' => $GLOBALS['facebook_config']['secret'],
-        'default_graph_version' => 'v2.2'
-    ]);
-
-    $helper = $fb->getRedirectLoginHelper();
-    $loginUrl = $helper->getLoginUrl(api_get_path(WEB_PATH) . '?action=fbconnect', [
-        'email'
-    ]);
-
-    return $loginUrl;
-}
-
-/**
- * Return a valid Chamilo login
- * Chamilo login only use characters lettres, des chiffres et les signes _ . -
- * @param $in_txt
- * @return mixed
- */
-function changeToValidChamiloLogin($in_txt)
-{
-    return preg_replace("/[^a-zA-Z1-9_\-.]/", "_", $in_txt);
-}
-
-/**
- * Get user language
- * @param string $language
- * @return bool
- */
-function facebookPluginGetLanguage($language = 'en_US')
-{
-    $language = substr($language, 0, 2);
-    $sqlResult = Database::query(
-        "SELECT english_name FROM ".
-        Database::get_main_table(TABLE_MAIN_LANGUAGE).
-        " WHERE available = 1 AND isocode = '$language'"
-    );
-    if (Database::num_rows($sqlResult)) {
-        $result = Database::fetch_array($sqlResult);
-        return $result['english_name'];
-    }
-
-    return false;
-}
-

+ 0 - 26
main/auth/external_login/facebook.init.php

@@ -1,26 +0,0 @@
-<?php
-
-/**
- * Licence: GPL
- * Please contact CBlue regarding any licences issues.
- * Author: noel@cblue.be
- *  Copyright: CBlue SPRL, 20XX
- *
- * External login module : FACEBOOK
- *
- * Configuration file 
- * Please edit this file to match with your FACEBOOK settings
- * */
-/**
- * Facebook application setting
- * */
-
-//Loads the portal facebook settings
-/**
- * Facebook application setting
- * Loads the portal facebook settings
- * See facebook section of the auth.conf.php file
- */
-
-require dirname(__FILE__) . '/../../../app/config/auth.conf.php';
-

+ 0 - 225
main/auth/external_login/functions.inc.php

@@ -1,225 +0,0 @@
-<?php
-
-//define('USERINFO_TABLE', 'danone_userinfo');
-//define('DEFAULT_PASSWORD', 'danonelearning');
-//TODO : Please implements this function for this module to work.
-/**
- * Gets user info from external source
- * @param string login
- * @param string password
- * @return user array with at least the following fields:
- *       firstname
- *       lastname
- *       status
- *       email
- *       login
- *       password
- *   or false if no data
- * */
-function external_get_user_info($login, $password)
-{
-    //Those are the mandatory fields for user creation.
-    //See external_add_user function for all the fields you can have.
-    $table = USERINFO_TABLE;
-    $sql = "SELECT * from $table where username='" . Database::escape_string($login) . "'";
-    $result = Database::query($sql);
-
-    if (Database::num_rows($result) == 0) { //false password
-        return false;
-    }
-    $user_info = Database::fetch_assoc($result);
-    // User status
-    $admin = false;
-    switch ($user_info['status']) {
-        case 'admin':
-            $status = COURSEMANAGER;
-            $admin = true;
-            break;
-        case 'teacher':
-            $status = COURSEMANAGER;
-            break;
-        case 'user':
-            $status = STUDENT;
-            break;
-        default:
-            $status = STUDENT;
-    }
-
-    // Language
-    switch ($user_info['language']) {
-        case 'FR':
-            $language = 'french';
-            break;
-        case 'EN':
-            $language = 'english';
-            break;
-        default:
-            $language = 'english';
-            break;
-    }
-    //Can Send Message ?
-    $can_send_message = ($user_info['can_send_message'] == 1) ? 'yes' : 'no';
-
-    $u = array(
-        'firstname' => $user_info['firstname'],
-        'lastname' => $user_info['lastname'],
-        'status' => $status,
-        'admin' => $admin,
-        'email' => $user_info['email'],
-        'username' => $user_info['username'],
-        'language' => $language,
-        'password' => DEFAULT_PASSWORD,
-        'courses' => $user_info['courses'],
-        'profile_link' => $user_info['profile_link'],
-        'worldwide_bu' => $user_info['worlwide_bu'],
-        'manager' => $user_info['manager'],
-        'extra' => array(
-            'position_title' => $user_info['position_title'],
-            'country' => $user_info['country'],
-            'job_family' => $user_info['job_family'],
-            'country_bu' => $user_info['country_bu'],
-            'worldwide_bu' => $user_info['worldwide_bu'],
-            'profile_link' => $user_info['profile_link'],
-            'can_send_message' => $can_send_message,
-            'update_type' => 'external_logininfo')
-    );
-
-    return $u; //Please return false if user does not exist
-    //return false;
-}
-
-/**
- * Return an array with all user info
- * @param associative array with at least thes fields setted :
-  firstname, lastname, status, email, login, password
- * @return mixed   new user id - if the new user creation succeeds, false otherwise
- * */
-function external_add_user($u)
-{
-    //Setting default
-    if (empty($u['password'])) {
-        $u['password'] = null;
-    }
-    if (empty($u['status'])) {
-        $u['status'] = 5;
-    }
-    if (!isset($u['official_code'])) {
-        $u['official_code'] = '';
-    }
-    if (!isset($u['language'])) {
-        $u['language'] = '';
-    }
-    if (!isset($u['phone'])) {
-        $u['phone'] = '';
-    }
-    if (!isset($u['picture_uri'])) {
-        $u['picture_uri'] = '';
-    }
-    if (!isset($u['auth_source'])) {
-        $u['auth_source'] = PLATFORM_AUTH_SOURCE;
-    }
-    if (!isset($u['expiration_date'])) {
-        $u['expiration_date'] = '';
-    }
-    if (!isset($u['active'])) {
-        $u['active'] = 1;
-    }
-    if (!isset($u['hr_dept_id'])) {
-        $u['hr_dept_id'] = 0;
-    } //id of responsible HR
-    if (!isset($u['extra'])) {
-        $u['extra'] = null;
-    }
-    if (!isset($u['encrypt_method'])) {
-        $u['encrypt_method'] = '';
-    }
-
-    $chamilo_uid = UserManager::create_user(
-        $u['firstname'],
-        $u['lastname'],
-        $u['status'],
-        $u['email'],
-        $u['username'],
-        $u['password'],
-        $u['official_code'],
-        $u['language'],
-        $u['phone'],
-        $u['picture_uri'],
-        $u['auth_source'],
-        $u['expiration_date'],
-        $u['active'],
-        $u['hr_dept_id'],
-        $u['extra'],
-        $u['encrypt_method']
-    );
-    return $chamilo_uid;
-}
-
-/**
- * Update the user in chamilo database. It upgrade only info that is present in the
- * new_user array
- *
- * @param $new_user associative array with the value to upgrade
- *    WARNING user_id key is MANDATORY
- *    Possible keys are :
- *      - firstname
- *      - lastname
- *      - username
- *      - auth_source
- *      - email
- *      - status
- *      - official_code
- *      - phone
- *      - picture_uri
- *      - expiration_date
- *      - active
- *      - creator_id
- *      - hr_dept_id
- *      - extra : array of custom fields
- *      - language
- *      - courses : string of all courses code separated by '|'
- *      - admin : boolean
- * @return boolean|null
- * @author ndiechburg <noel@cblue.be>
- * */
-function external_update_user($new_user)
-{
-    $old_user = api_get_user_info($new_user['user_id']);
-    $u = array_merge($old_user, $new_user);
-    $updated = UserManager::update_user(
-        $u['user_id'],
-        $u['firstname'],
-        $u['lastname'],
-        $u['username'],
-        null,
-        $u['auth_source'],
-        $u['email'],
-        $u['status'],
-        $u['official_code'],
-        $u['phone'],
-        $u['picture_uri'],
-        $u['expiration_date'],
-        $u['active'],
-        $u['creator_id'],
-        $u['hr_dept_id'],
-        $u['extra'],
-        $u['language'],
-        ''
-    );
-    if (isset($u['courses']) && !empty($u['courses'])) {
-        $autoSubscribe = explode('|', $u['courses']);
-        foreach ($autoSubscribe as $code) {
-            if (CourseManager::course_exists($code)) {
-                CourseManager::subscribe_user($u['user_id'], $code);
-            }
-        }
-    }
-    // Is User Admin ?
-    //TODO decomments and check that user_is is not already in admin table
-    /*
-      if (isset($u['admin']) && $u['admin']){
-
-      $table = Database::get_main_table(TABLE_MAIN_ADMIN);
-      $res = Database::query("SELECT * from $table WHERE user_id = ".$u['user_id']);
-      } */
-}