Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/auth/fc/auth.php
Go to the documentation of this file.
00001 <?php
00014 if (!defined('MOODLE_INTERNAL')) {
00015     die('Direct access to this script is forbidden.');    
00016 }
00017 
00018 require_once($CFG->libdir.'/authlib.php');
00019 
00020 require_once 'fcFPP.php';
00021 
00025 class auth_plugin_fc extends auth_plugin_base {
00026 
00030     function auth_plugin_fc() {
00031         $this->authtype = 'fc';
00032         $this->config = get_config('auth/fc');
00033     }
00034 
00043     function user_login ($username, $password) {
00044         global $CFG;
00045         $retval = false;
00046 
00047         // Don't allow blank usernames or passwords
00048         if (!$username or !$password) {
00049             return $retval;
00050         }
00051 
00052         $fpp = new fcFPP($this->config->host, $this->config->fppport);
00053         if ($fpp->open()) {
00054             if ($fpp->login($username, $password)) {
00055                 $retval = true;
00056             }
00057         }
00058         $fpp->close();
00059 
00060         return $retval;
00061     }
00062 
00067     function get_userinfo($username) {
00068         /*
00069         Moodle                FirstCLass fieldID in UserInfo form
00070         ------                -----------------------------------
00071         firstname             1202
00072         lastname              1204
00073         email                 1252
00074         icq                   -
00075         phone1                1206
00076         phone2                1207 (Fax)
00077         institution           -
00078         department            -
00079         address               1205
00080         city                  -
00081         country               -
00082         lang                  -
00083         timezone              8030 (Not used yet. Need to figure out how FC codes timezones)
00084 
00085         description           Get data from users resume. Pictures will be removed.
00086 
00087         */
00088 
00089         $userinfo = array();
00090 
00091         $fpp = new fcFPP($this->config->host, $this->config->fppport);
00092         if ($fpp->open()) {
00093             if ($fpp->login($this->config->userid, $this->config->passwd)) {
00094                 $userinfo['firstname']   = $fpp->getUserInfo($username,"1202");
00095                 $userinfo['lastname']    = $fpp->getUserInfo($username,"1204");
00096                 $userinfo['email']       = strtok($fpp->getUserInfo($username,"1252"),',');
00097                 $userinfo['phone1']      = $fpp->getUserInfo($username,"1206");
00098                 $userinfo['phone2']      = $fpp->getUserInfo($username,"1207");
00099                 $userinfo['description'] = $fpp->getResume($username);
00100             }
00101         }
00102         $fpp->close();
00103 
00104         foreach($userinfo as $key => $value) {
00105             if (!$value) {
00106                 unset($userinfo[$key]);
00107             }
00108         }
00109 
00110         return $userinfo;
00111     }
00112 
00117     function iscreator($username) {
00118         if (! $this->config->creators) {
00119             return null;
00120         }
00121 
00122         $fcgroups = array();
00123 
00124         $fpp = new fcFPP($this->config->host, $this->config->fppport);
00125         if ($fpp->open()) {
00126             if ($fpp->login($this->config->userid, $this->config->passwd)) {
00127                 $fcgroups = $fpp->getGroups($username);
00128             }
00129         }
00130         $fpp->close();
00131 
00132         if ((! $fcgroups)) {
00133             return false;
00134         }
00135 
00136         $creators = explode(";", $this->config->creators);
00137 
00138         foreach($creators as $creator) {
00139             if (in_array($creator, $fcgroups)) {
00140                 return true;
00141             }
00142         }
00143 
00144         return false;
00145     }
00146 
00147     function prevent_local_passwords() {
00148         return true;
00149     }
00150 
00156     function is_internal() {
00157         return false;
00158     }
00159 
00166     function can_change_password() {
00167         return false;
00168     }
00169 
00175     function sync_roles($user) {
00176         $iscreator = $this->iscreator($user->username);
00177         if ($iscreator === null) {
00178             return; //nothing to sync - creators not configured
00179         }
00180 
00181         if ($roles = get_archetype_roles('coursecreator')) {
00182             $creatorrole = array_shift($roles);      // We can only use one, let's use the first one
00183             $systemcontext = get_context_instance(CONTEXT_SYSTEM);
00184 
00185             if ($iscreator) { // Following calls will not create duplicates
00186                 role_assign($creatorrole->id, $user->id, $systemcontext->id, 'auth_fc');
00187             } else {
00188                 //unassign only if previously assigned by this plugin!
00189                 role_unassign($creatorrole->id, $user->id, $systemcontext->id, 'auth_fc');
00190             }
00191         }
00192     }
00193 
00202     function config_form($config, $err, $user_fields) {
00203         include "config.html";
00204     }
00205 
00209     function process_config($config) {
00210         // set to defaults if undefined
00211         if (!isset($config->host)) {
00212             $config->host = "127.0.0.1";
00213         }
00214         if (!isset($config->fppport)) {
00215             $config->fppport = "3333";
00216         }
00217         if (!isset($config->userid)) {
00218             $config->userid = "fcMoodle";
00219         }
00220         if (!isset($config->passwd)) {
00221             $config->passwd = "";
00222         }
00223         if (!isset($config->creators)) {
00224             $config->creators = "";
00225         }
00226         if (!isset($config->changepasswordurl)) {
00227             $config->changepasswordurl = '';
00228         }
00229 
00230         // save settings
00231         set_config('host',      $config->host,     'auth/fc');
00232         set_config('fppport',   $config->fppport,  'auth/fc');
00233         set_config('userid',    $config->userid,   'auth/fc');
00234         set_config('passwd',    $config->passwd,   'auth/fc');
00235         set_config('creators',  $config->creators, 'auth/fc');
00236         set_config('changepasswordurl', $config->changepasswordurl, 'auth/fc');
00237 
00238         return true;
00239     }
00240 
00241 }
00242 
00243 
 All Data Structures Namespaces Files Functions Variables Enumerations