Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/auth/imap/auth.php
Go to the documentation of this file.
00001 <?php
00002 
00015 if (!defined('MOODLE_INTERNAL')) {
00016     die('Direct access to this script is forbidden.');    
00017 }
00018 
00019 require_once($CFG->libdir.'/authlib.php');
00020 
00024 class auth_plugin_imap extends auth_plugin_base {
00025 
00029     function auth_plugin_imap() {
00030         $this->authtype = 'imap';
00031         $this->config = get_config('auth/imap');
00032     }
00033 
00042     function user_login ($username, $password) {
00043         if (! function_exists('imap_open')) {
00044             print_error('auth_imapnotinstalled','mnet');
00045             return false;
00046         }
00047 
00048         global $CFG;
00049         $hosts = explode(';', $this->config->host);   // Could be multiple hosts
00050 
00051         foreach ($hosts as $host) {                 // Try each host in turn
00052             $host = trim($host);
00053 
00054             switch ($this->config->type) {
00055                 case 'imapssl':
00056                     $host = '{'.$host.":{$this->config->port}/imap/ssl}";
00057                 break;
00058 
00059                 case 'imapcert':
00060                     $host = '{'.$host.":{$this->config->port}/imap/ssl/novalidate-cert}";
00061                 break;
00062 
00063                 case 'imaptls':
00064                     $host = '{'.$host.":{$this->config->port}/imap/tls}";
00065                 break;
00066 
00067                 default:
00068                     $host = '{'.$host.":{$this->config->port}/imap}";
00069             }
00070 
00071             error_reporting(0);
00072             $connection = imap_open($host, $username, $password, OP_HALFOPEN);
00073             error_reporting($CFG->debug);
00074 
00075             if ($connection) {
00076                 imap_close($connection);
00077                 return true;
00078             }
00079         }
00080 
00081         return false;  // No match
00082     }
00083 
00084     function prevent_local_passwords() {
00085         return true;
00086     }
00087 
00093     function is_internal() {
00094         return false;
00095     }
00096 
00103     function can_change_password() {
00104         return !empty($this->config->changepasswordurl);
00105     }
00106 
00113     function change_password_url() {
00114         return new moodle_url($this->config->changepasswordurl);
00115     }
00116 
00125     function config_form($config, $err, $user_fields) {
00126         global $OUTPUT;
00127 
00128         include "config.html";
00129     }
00130 
00134     function process_config($config) {
00135         // set to defaults if undefined
00136         if (!isset ($config->host)) {
00137             $config->host = '127.0.0.1';
00138         }
00139         if (!isset ($config->type)) {
00140             $config->type = 'imap';
00141         }
00142         if (!isset ($config->port)) {
00143             $config->port = '143';
00144         }
00145         if (!isset($config->changepasswordurl)) {
00146             $config->changepasswordurl = '';
00147         }
00148 
00149         // save settings
00150         set_config('host', $config->host, 'auth/imap');
00151         set_config('type', $config->type, 'auth/imap');
00152         set_config('port', $config->port, 'auth/imap');
00153         set_config('changepasswordurl', $config->changepasswordurl, 'auth/imap');
00154 
00155         return true;
00156     }
00157 
00158 }
00159 
00160 
 All Data Structures Namespaces Files Functions Variables Enumerations