Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/auth/pop3/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_pop3 extends auth_plugin_base {
00025 
00029     function auth_plugin_pop3() {
00030         $this->authtype = 'pop3';
00031         $this->config = get_config('auth/pop3');
00032     }
00033 
00042     function user_login($username, $password) {
00043         if (! function_exists('imap_open')) {
00044             print_error('auth_pop3notinstalled','auth_pop3');
00045             exit;
00046         }
00047 
00048         global $CFG;
00049         $hosts = explode(';', $this->config->host);   // Could be multiple hosts
00050         foreach ($hosts as $host) {                 // Try each host in turn
00051             $host = trim($host);
00052 
00053             // remove any trailing slash
00054             if (substr($host, -1) == '/') {
00055                 $host = substr($host, 0, strlen($host) - 1);
00056             }
00057 
00058             switch ($this->config->type) {
00059                 case 'pop3':
00060                     $host = '{'.$host.":{$this->config->port}/pop3}{$this->config->mailbox}";
00061                 break;
00062 
00063                 case 'pop3notls':
00064                     $host = '{'.$host.":{$this->config->port}/pop3/notls}{$this->config->mailbox}";
00065                 break;
00066 
00067                 case 'pop3cert':
00068                     $host = '{'.$host.":{$this->config->port}/pop3/ssl/novalidate-cert}{$this->config->mailbox}";
00069                 break;
00070             }
00071 
00072             error_reporting(0);
00073             $connection = imap_open($host, $username, $password);
00074             error_reporting($CFG->debug);
00075 
00076             if ($connection) {
00077                 imap_close($connection);
00078                 return true;
00079             }
00080         }
00081         return false;  // No matches found
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 = 'pop3notls';
00141         }
00142         if (!isset ($config->port)) {
00143             $config->port = '143';
00144         }
00145         if (!isset ($config->mailbox)) {
00146             $config->mailbox = 'INBOX';
00147         }
00148         if (!isset($config->changepasswordurl)) {
00149             $config->changepasswordurl = '';
00150         }
00151 
00152         // save settings
00153         set_config('host',    $config->host,    'auth/pop3');
00154         set_config('type',    $config->type,    'auth/pop3');
00155         set_config('port',    $config->port,    'auth/pop3');
00156         set_config('mailbox', $config->mailbox, 'auth/pop3');
00157         set_config('changepasswordurl', $config->changepasswordurl, 'auth/pop3');
00158 
00159         return true;
00160     }
00161 
00162 }
00163 
00164 
 All Data Structures Namespaces Files Functions Variables Enumerations