Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/auth/email/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_email extends auth_plugin_base {
00025 
00029     function auth_plugin_email() {
00030         $this->authtype = 'email';
00031         $this->config = get_config('auth/email');
00032     }
00033 
00042     function user_login ($username, $password) {
00043         global $CFG, $DB;
00044         if ($user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
00045             return validate_internal_user_password($user, $password);
00046         }
00047         return false;
00048     }
00049 
00060     function user_update_password($user, $newpassword) {
00061         $user = get_complete_user_data('id', $user->id);
00062         return update_internal_user_password($user, $newpassword);
00063     }
00064 
00065     function can_signup() {
00066         return true;
00067     }
00068 
00076     function user_signup($user, $notify=true) {
00077         global $CFG, $DB;
00078         require_once($CFG->dirroot.'/user/profile/lib.php');
00079 
00080         $user->password = hash_internal_user_password($user->password);
00081 
00082         $user->id = $DB->insert_record('user', $user);
00083 
00085         profile_save_data($user);
00086 
00087         $user = $DB->get_record('user', array('id'=>$user->id));
00088         events_trigger('user_created', $user);
00089 
00090         if (! send_confirmation_email($user)) {
00091             print_error('auth_emailnoemail','auth_email');
00092         }
00093 
00094         if ($notify) {
00095             global $CFG, $PAGE, $OUTPUT;
00096             $emailconfirm = get_string('emailconfirm');
00097             $PAGE->navbar->add($emailconfirm);
00098             $PAGE->set_title($emailconfirm);
00099             $PAGE->set_heading($PAGE->course->fullname);
00100             echo $OUTPUT->header();
00101             notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
00102         } else {
00103             return true;
00104         }
00105     }
00106 
00112     function can_confirm() {
00113         return true;
00114     }
00115 
00122     function user_confirm($username, $confirmsecret) {
00123         global $DB;
00124         $user = get_complete_user_data('username', $username);
00125 
00126         if (!empty($user)) {
00127             if ($user->confirmed) {
00128                 return AUTH_CONFIRM_ALREADY;
00129 
00130             } else if ($user->auth != 'email') {
00131                 return AUTH_CONFIRM_ERROR;
00132 
00133             } else if ($user->secret == $confirmsecret) {   // They have provided the secret key to get in
00134                 $DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
00135                 $DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
00136                 return AUTH_CONFIRM_OK;
00137             }
00138         } else {
00139             return AUTH_CONFIRM_ERROR;
00140         }
00141     }
00142 
00143     function prevent_local_passwords() {
00144         return false;
00145     }
00146 
00152     function is_internal() {
00153         return true;
00154     }
00155 
00162     function can_change_password() {
00163         return true;
00164     }
00165 
00172     function change_password_url() {
00173         return null; // use default internal method
00174     }
00175 
00181     function can_reset_password() {
00182         return true;
00183     }
00184 
00193     function config_form($config, $err, $user_fields) {
00194         include "config.html";
00195     }
00196 
00200     function process_config($config) {
00201         // set to defaults if undefined
00202         if (!isset($config->recaptcha)) {
00203             $config->recaptcha = false;
00204         }
00205 
00206         // save settings
00207         set_config('recaptcha', $config->recaptcha, 'auth/email');
00208         return true;
00209     }
00210 
00215     function is_captcha_enabled() {
00216         global $CFG;
00217         return isset($CFG->recaptchapublickey) && isset($CFG->recaptchaprivatekey) && get_config("auth/{$this->authtype}", 'recaptcha');
00218     }
00219 
00220 }
00221 
00222 
 All Data Structures Namespaces Files Functions Variables Enumerations