MDL-9004 - Breadcrumb trail is wrong when editing a quiz question. Merged from MOODLE...
[moodle.git] / auth / email / auth.php
CommitLineData
b9ddb2d5 1<?php
2
3/**
4 * @author Martin Dougiamas
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package moodle multiauth
7 *
8 * Authentication Plugin: Email Authentication
9 *
10 * Standard authentication function.
11 *
12 * 2006-08-28 File created.
13 */
14
139ebfdb 15if (!defined('MOODLE_INTERNAL')) {
16 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
17}
b9ddb2d5 18
b9ddb2d5 19
20/**
21 * Email authentication plugin.
22 */
23class auth_plugin_email {
24
25 /**
26 * The configuration details for the plugin.
27 */
28 var $config;
29
30 /**
31 * Constructor.
32 */
33 function auth_plugin_email() {
34 $this->config = get_config('auth/email');
35 }
36
37 /**
38 * Returns true if the username and password work and false if they are
39 * wrong or don't exist.
40 *
41 * @param string $username The username
42 * @param string $password The password
139ebfdb 43 * @return bool Authentication success or failure.
b9ddb2d5 44 */
45 function user_login ($username, $password) {
b7b50143 46 global $CFG;
47 if ($user = get_record('user', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id)) {
b9ddb2d5 48 return validate_internal_user_password($user, $password);
49 }
50 return false;
51 }
52
fb5c7739 53 /**
b9ddb2d5 54 * Updates the user's password.
55 *
56 * called when the user password is updated.
57 *
c57dcb62 58 * @param object $user User table object (with system magic quotes)
59 * @param string $newpassword Plaintext password (with system magic quotes)
b9ddb2d5 60 * @return boolean result
61 *
62 */
da249a30 63 function user_update_password($user, $newpassword) {
64 $user = get_complete_user_data('id', $user->id);
b9ddb2d5 65 return update_internal_user_password($user, $newpassword);
66 }
67
430759a5 68 /**
b9ddb2d5 69 * Sign up a new user ready for confirmation.
dd0feda5 70 * Password is passed in plaintext.
71 *
72 * @param object $user new user object (with system magic quotes)
73 * @param boolean $notify print notice with link and terminate
b9ddb2d5 74 */
75 function user_signup($user, $notify = true) {
dd0feda5 76 $user->password = hash_internal_user_password($user->password);
77
b9ddb2d5 78 if (! ($user->id = insert_record('user', $user)) ) {
a9ad3633 79 print_error('auth_emailnoinsert','auth');
b9ddb2d5 80 }
81 if (! send_confirmation_email($user)) {
a9ad3633 82 print_error('auth_emailnoemail','auth');
b9ddb2d5 83 }
84
85 if ($notify) {
86 global $CFG;
87 $emailconfirm = get_string('emailconfirm');
88 print_header($emailconfirm, $emailconfirm, $emailconfirm);
89 notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
dd0feda5 90 } else {
91 return true;
139ebfdb 92 }
b9ddb2d5 93 }
94
430759a5 95 /**
b9ddb2d5 96 * Confirm the new user as registered.
dd0feda5 97 *
98 * @param string $username (with system magic quotes)
99 * @param string $confirmsecret (with system magic quotes)
b9ddb2d5 100 */
101 function user_confirm($username, $confirmsecret) {
102 $user = get_complete_user_data('username', $username);
103
104 if (!empty($user)) {
105 if ($user->confirmed) {
106 return AUTH_CONFIRM_ALREADY;
dd0feda5 107
108 } else if ($user->auth != 'email') {
109 return AUTH_CONFIRM_ERROR;
110
111 } else if ($user->secret == stripslashes($confirmsecret)) { // They have provided the secret key to get in
b9ddb2d5 112 if (!set_field("user", "confirmed", 1, "id", $user->id)) {
113 return AUTH_CONFIRM_FAIL;
114 }
115 if (!set_field("user", "firstaccess", time(), "id", $user->id)) {
116 return AUTH_CONFIRM_FAIL;
117 }
118 return AUTH_CONFIRM_OK;
119 }
dd0feda5 120 } else {
121 return AUTH_CONFIRM_ERROR;
b9ddb2d5 122 }
123 }
124
125 /**
126 * Returns true if this authentication plugin is 'internal'.
127 *
139ebfdb 128 * @return bool
b9ddb2d5 129 */
130 function is_internal() {
131 return true;
132 }
139ebfdb 133
b9ddb2d5 134 /**
135 * Returns true if this authentication plugin can change the user's
136 * password.
137 *
139ebfdb 138 * @return bool
b9ddb2d5 139 */
140 function can_change_password() {
141 return true;
142 }
139ebfdb 143
b9ddb2d5 144 /**
430759a5 145 * Returns the URL for changing the user's pw, or empty if the default can
b9ddb2d5 146 * be used.
147 *
430759a5 148 * @return mixed
b9ddb2d5 149 */
150 function change_password_url() {
430759a5 151 return ''; // use dafult internal method
152 }
153
154 /**
155 * Returns true if plugin allows resetting of internal password.
156 *
157 * @return bool
158 */
159 function can_reset_password() {
160 return true;
b9ddb2d5 161 }
139ebfdb 162
b9ddb2d5 163 /**
164 * Prints a form for configuring this authentication plugin.
165 *
166 * This function is called from admin/auth.php, and outputs a full page with
167 * a form for configuring this plugin.
168 *
169 * @param array $page An object containing all the data for this page.
170 */
139ebfdb 171 function config_form($config, $err, $user_fields) {
b9ddb2d5 172 include "config.html";
173 }
174
175 /**
176 * Processes and stores configuration data for this authentication plugin.
177 */
178 function process_config($config) {
179 return true;
180 }
139ebfdb 181
b9ddb2d5 182}
183
184?>