Julio Montoya 13 years ago
parent
commit
be27d9e6da

+ 13 - 2
main/auth/external_login/facebook.inc.php

@@ -1,6 +1,6 @@
 <?php
 /**
- * Licence: GPL
+ * Licence: GPL 
  * Please contact CBlue regarding any licences issues.
  * Author: noel@cblue.be
  *  Copyright: CBlue SPRL, 20XX
@@ -28,7 +28,10 @@ function facebook_connect() {
 		try {
 			//Gets facebook user info
 			$fu = $facebook->api('/me');
-			$username = api_get_setting('login_is_email') == 'true' ? $fu['email'] : $fu['username'];
+			$username = $fu['username'];
+			if (api_get_setting('login_is_email') == 'true' || empty($fu['username'])) {
+			    $username = change_to_valid_chamilo_login($fu['email']);
+			}
 			//Checks if user already exists in chamilo
 			$u = array(
 					'firstname' => $fu['first_name'],
@@ -91,3 +94,11 @@ function facebook_get_login_url(){
 	return $login_url;
 }
 
+/**
+ * @input : a string
+ * @return : a string containing valid chamilo login characters
+ * Chamilo login only use characters lettres, des chiffres et les signes _ . -
+**/
+function change_to_valid_chamilo_login($in_txt) {
+    return preg_replace("/[^a-zA-Z1-9_\-.]/", "_", $in_txt);exit;
+}

+ 12 - 0
plugin/add_facebook_login_button/css.css

@@ -0,0 +1,12 @@
+    .cas_plugin_image {
+        float:left; 
+        height:50px;
+        margin: 0px 5px 5px 0px;        
+    }
+    .cas_plugin_comm {
+        font-style:italic;
+    }
+    .cas_plugin_clear {
+        clear:both;
+        height:1px;
+    }

BIN
plugin/add_facebook_login_button/img/cnx_fb.png


+ 0 - 0
plugin/add_facebook_login_button/img/index.html


+ 21 - 0
plugin/add_facebook_login_button/index.php

@@ -0,0 +1,21 @@
+<?php
+// Show the FACEBOOK login button
+
+$_template['show_message']   = false;
+
+//if (api_is_anonymous() && api_get_setting('facebook_login_activate') == 'true') {
+if (api_is_anonymous()) {
+    require_once(api_get_path(SYS_CODE_PATH)."auth/external_login/facebook.conf.php");
+    $_template['show_message']   = true;
+    // the default title
+    $button_url = api_get_path(WEB_PLUGIN_PATH)."add_facebook_login_button/img/cnx_fb.png";
+    $href_link = facebook_get_login_url();
+    if (!empty($plugin_info['settings']['add_facebook_login_button_facebook_button_url'])) {
+        $button_url = api_htmlentities($plugin_info['settings']['add_facebook_login_button_facebook_button_url']);
+    }
+    
+    $_template['facebook_button_url'] = $button_url;
+    $_template['facebook_href_link'] = $href_link;
+    
+    
+}

+ 35 - 0
plugin/add_facebook_login_button/plugin.php

@@ -0,0 +1,35 @@
+<?php
+/**
+ * This script is a configuration file for the date plugin. You can use it as a master for other platform plugins (course plugins are slightly different).
+ * These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins)
+ * @package chamilo.plugin
+ * @author Julio Montoya <gugli100@gmail.com>
+ */
+/**
+ * Plugin details (must be present)
+ */
+
+
+
+//the plugin title
+$plugin_info['title']      = 'Add a button to login using FACEBOOK account';
+
+//the comments that go with the plugin
+$plugin_info['comment']     = "If Facebook authntification is activated, this plugin add a button Facebook Connexion on the login page. Configure plugin to add title, comment and logo. Should be place in login_top region";
+//the plugin version
+$plugin_info['version']     = '1.0';
+//the plugin author
+$plugin_info['author']      = 'Hubert Borderiou';
+//the plugin configuration
+$form = new FormValidator('add_facebook_button_form');
+$form->addElement('text', 'facebook_button_url', 'Facebook connexion image URL', '');
+$form->addElement('style_submit_button', 'submit_button', get_lang('Save'));  
+//get default value for form
+$tab_default_add_facebook_login_button_facebook_button_url = api_get_setting('add_facebook_login_button_facebook_button_url');
+$defaults['facebook_button_url'] = $tab_default_add_facebook_login_button_facebook_button_url['add_facebook_login_button'];
+$form->setDefaults($defaults);
+//display form
+$plugin_info['settings_form'] = $form;
+
+//set the smarty templates that are going to be used
+$plugin_info['templates']   = array('template.tpl');

+ 7 - 0
plugin/add_facebook_login_button/readme.txt

@@ -0,0 +1,7 @@
+README
+<br/><br/>
+This plugin add a button to allow user to login to Chamilo with there Facebook account.<br/><br/>
+You have to activate your Facebook authentification to display this button.<br/>
+You have to configure your Facebook authentification to have the button works.<br/>
+To activate and configure Facebook authentification, for your Chamilo platform, go to Administration > Configuration settings > Facebook<br/>
+This plugin has been done to be added in the login_top region, but you can put it where you want.<br/>

+ 37 - 0
plugin/add_facebook_login_button/template.tpl

@@ -0,0 +1,37 @@
+{#
+    This is a Chamilo plugin using Smarty you can use handy shorcuts like:
+    
+    1. Shortcuts 
+    
+    $_p = url chamilo paths
+    $_u = user information of the current user
+    
+    2. i18n
+    
+    You can use i18n variables just use this syntax:
+    
+    {"HelloWorld"|get_lang}
+    
+    Now you can add your variables in the main/lang/english/ or main/lang/spanish/ for example in spanish:    
+    $HelloWorld = "Hola Mundo";
+    
+    3. Portal settings
+    
+        You can access the portal settings using:
+        {"siteName"|api_get_setting}
+        For more settings check the settings_current database
+        
+    4. Read more
+        You can also see more examples in the the main/template/default/layout files
+        
+    5. {$_p|var_dump} pour les path {$_u|var_dump} pour info de  l'utilisateur loggé
+#}
+
+
+{% if add_facebook_login_button.show_message %}
+    <div class="well">
+        <a href="{{add_facebook_login_button.facebook_href_link}}">
+            <img src="{{add_facebook_login_button.facebook_button_url}}"/>
+        </a>
+    </div>
+{% endif %}