'added CSS for white-space:nowrap in styles_layout and took the hardcoded inline...
[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
19/**
20 * Error codes for user confirm
21 */
22define('AUTH_CONFIRM_FAIL', 0);
23define('AUTH_CONFIRM_OK', 1);
24define('AUTH_CONFIRM_ALREADY', 2);
25define('AUTH_CONFIRM_ERROR', 3);
26// TODO: instead of integers these could be the language keys?
27
28
29/**
30 * Email authentication plugin.
31 */
32class auth_plugin_email {
33
34 /**
35 * The configuration details for the plugin.
36 */
37 var $config;
38
39 /**
40 * Constructor.
41 */
42 function auth_plugin_email() {
43 $this->config = get_config('auth/email');
44 }
45
46 /**
47 * Returns true if the username and password work and false if they are
48 * wrong or don't exist.
49 *
50 * @param string $username The username
51 * @param string $password The password
139ebfdb 52 * @return bool Authentication success or failure.
b9ddb2d5 53 */
54 function user_login ($username, $password) {
b7b50143 55 global $CFG;
56 if ($user = get_record('user', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id)) {
b9ddb2d5 57 return validate_internal_user_password($user, $password);
58 }
59 return false;
60 }
61
fb5c7739 62 /**
b9ddb2d5 63 * Updates the user's password.
64 *
65 * called when the user password is updated.
66 *
fb5c7739 67 * @param object $user User
68 * @param string $newpassword Plaintext password
b9ddb2d5 69 * @return boolean result
70 *
71 */
da249a30 72 function user_update_password($user, $newpassword) {
73 $user = get_complete_user_data('id', $user->id);
b9ddb2d5 74 return update_internal_user_password($user, $newpassword);
75 }
76
77 /*
78 * Sign up a new user ready for confirmation.
79 */
80 function user_signup($user, $notify = true) {
81 if (! ($user->id = insert_record('user', $user)) ) {
a9ad3633 82 print_error('auth_emailnoinsert','auth');
b9ddb2d5 83 }
84 if (! send_confirmation_email($user)) {
a9ad3633 85 print_error('auth_emailnoemail','auth');
b9ddb2d5 86 }
87
88 if ($notify) {
89 global $CFG;
90 $emailconfirm = get_string('emailconfirm');
91 print_header($emailconfirm, $emailconfirm, $emailconfirm);
92 notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
139ebfdb 93 }
b9ddb2d5 94 }
95
96 /*
97 * Confirm the new user as registered.
98 */
99 function user_confirm($username, $confirmsecret) {
100 $user = get_complete_user_data('username', $username);
101
102 if (!empty($user)) {
103 if ($user->confirmed) {
104 return AUTH_CONFIRM_ALREADY;
105 }
106 if ($user->secret == $confirmsecret) { // They have provided the secret key to get in
107 if (!set_field("user", "confirmed", 1, "id", $user->id)) {
108 return AUTH_CONFIRM_FAIL;
109 }
110 if (!set_field("user", "firstaccess", time(), "id", $user->id)) {
111 return AUTH_CONFIRM_FAIL;
112 }
113 return AUTH_CONFIRM_OK;
114 }
115 }
116 }
117
118 /**
119 * Returns true if this authentication plugin is 'internal'.
120 *
139ebfdb 121 * @return bool
b9ddb2d5 122 */
123 function is_internal() {
124 return true;
125 }
139ebfdb 126
b9ddb2d5 127 /**
128 * Returns true if this authentication plugin can change the user's
129 * password.
130 *
139ebfdb 131 * @return bool
b9ddb2d5 132 */
133 function can_change_password() {
134 return true;
135 }
139ebfdb 136
b9ddb2d5 137 /**
138 * Returns the URL for changing the user's pw, or false if the default can
139 * be used.
140 *
139ebfdb 141 * @return bool
b9ddb2d5 142 */
143 function change_password_url() {
144 return false;
145 }
139ebfdb 146
b9ddb2d5 147 /**
148 * Prints a form for configuring this authentication plugin.
149 *
150 * This function is called from admin/auth.php, and outputs a full page with
151 * a form for configuring this plugin.
152 *
153 * @param array $page An object containing all the data for this page.
154 */
139ebfdb 155 function config_form($config, $err, $user_fields) {
b9ddb2d5 156 include "config.html";
157 }
158
159 /**
160 * Processes and stores configuration data for this authentication plugin.
161 */
162 function process_config($config) {
163 return true;
164 }
139ebfdb 165
b9ddb2d5 166}
167
168?>