Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / auth / email / auth.php
blob20ad9232efaa48107d020ebef2f6ac9e172bca92
1 <?php
3 /**
4 * @author Martin Dougiamas
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package moodle multiauth
8 * Authentication Plugin: Email Authentication
10 * Standard authentication function.
12 * 2006-08-28 File created.
15 if (!defined('MOODLE_INTERNAL')) {
16 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
19 require_once($CFG->libdir.'/authlib.php');
21 /**
22 * Email authentication plugin.
24 class auth_plugin_email extends auth_plugin_base {
26 /**
27 * Constructor.
29 function auth_plugin_email() {
30 $this->authtype = 'email';
31 $this->config = get_config('auth/email');
34 /**
35 * Returns true if the username and password work and false if they are
36 * wrong or don't exist.
38 * @param string $username The username
39 * @param string $password The password
40 * @return bool Authentication success or failure.
42 function user_login ($username, $password) {
43 global $CFG;
44 if ($user = get_record('user', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id)) {
45 return validate_internal_user_password($user, $password);
47 return false;
50 /**
51 * Updates the user's password.
53 * called when the user password is updated.
55 * @param object $user User table object (with system magic quotes)
56 * @param string $newpassword Plaintext password (with system magic quotes)
57 * @return boolean result
60 function user_update_password($user, $newpassword) {
61 $user = get_complete_user_data('id', $user->id);
62 return update_internal_user_password($user, $newpassword);
65 function can_signup() {
66 return true;
69 /**
70 * Sign up a new user ready for confirmation.
71 * Password is passed in plaintext.
73 * @param object $user new user object (with system magic quotes)
74 * @param boolean $notify print notice with link and terminate
76 function user_signup($user, $notify=true) {
77 $user->password = hash_internal_user_password($user->password);
79 if (! ($user->id = insert_record('user', $user)) ) {
80 print_error('auth_emailnoinsert','auth');
82 if (! send_confirmation_email($user)) {
83 print_error('auth_emailnoemail','auth');
86 if ($notify) {
87 global $CFG;
88 $emailconfirm = get_string('emailconfirm');
89 print_header($emailconfirm, $emailconfirm, $emailconfirm);
90 notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
91 } else {
92 return true;
96 /**
97 * Returns true if plugin allows confirming of new users.
99 * @return bool
101 function can_confirm() {
102 return true;
106 * Confirm the new user as registered.
108 * @param string $username (with system magic quotes)
109 * @param string $confirmsecret (with system magic quotes)
111 function user_confirm($username, $confirmsecret) {
112 $user = get_complete_user_data('username', $username);
114 if (!empty($user)) {
115 if ($user->confirmed) {
116 return AUTH_CONFIRM_ALREADY;
118 } else if ($user->auth != 'email') {
119 return AUTH_CONFIRM_ERROR;
121 } else if ($user->secret == stripslashes($confirmsecret)) { // They have provided the secret key to get in
122 if (!set_field("user", "confirmed", 1, "id", $user->id)) {
123 return AUTH_CONFIRM_FAIL;
125 if (!set_field("user", "firstaccess", time(), "id", $user->id)) {
126 return AUTH_CONFIRM_FAIL;
128 return AUTH_CONFIRM_OK;
130 } else {
131 return AUTH_CONFIRM_ERROR;
136 * Returns true if this authentication plugin is 'internal'.
138 * @return bool
140 function is_internal() {
141 return true;
145 * Returns true if this authentication plugin can change the user's
146 * password.
148 * @return bool
150 function can_change_password() {
151 return true;
155 * Returns the URL for changing the user's pw, or empty if the default can
156 * be used.
158 * @return mixed
160 function change_password_url() {
161 return ''; // use dafult internal method
165 * Returns true if plugin allows resetting of internal password.
167 * @return bool
169 function can_reset_password() {
170 return true;
174 * Prints a form for configuring this authentication plugin.
176 * This function is called from admin/auth.php, and outputs a full page with
177 * a form for configuring this plugin.
179 * @param array $page An object containing all the data for this page.
181 function config_form($config, $err, $user_fields) {
182 include "config.html";
186 * Processes and stores configuration data for this authentication plugin.
188 function process_config($config) {
189 return true;