MDL-34702 quiz DB: fix non-matching savepoint
[moodle.git] / auth / manual / auth.php
blob29cb59ae2ef0952f81b43547d8d02c8d72fd05e4
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Authentication Plugin: Manual Authentication
19 * Just does a simple check against the moodle database.
21 * @package auth
22 * @subpackage manual
23 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
29 require_once($CFG->libdir.'/authlib.php');
31 /**
32 * Manual authentication plugin.
34 * @package auth
35 * @subpackage manual
36 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class auth_plugin_manual extends auth_plugin_base {
41 /**
42 * Constructor.
44 function auth_plugin_manual() {
45 $this->authtype = 'manual';
46 $this->config = get_config('auth/manual');
49 /**
50 * Returns true if the username and password work and false if they are
51 * wrong or don't exist. (Non-mnet accounts only!)
53 * @param string $username The username
54 * @param string $password The password
55 * @return bool Authentication success or failure.
57 function user_login($username, $password) {
58 global $CFG, $DB, $USER;
59 if (!$user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
60 return false;
62 if (!validate_internal_user_password($user, $password)) {
63 return false;
65 if ($password === 'changeme') {
66 // force the change - this is deprecated and it makes sense only for manual auth,
67 // because most other plugins can not change password easily or
68 // passwords are always specified by users
69 set_user_preference('auth_forcepasswordchange', true, $user->id);
71 return true;
74 /**
75 * Updates the user's password.
77 * Called when the user password is updated.
79 * @param object $user User table object
80 * @param string $newpassword Plaintext password
81 * @return boolean result
83 function user_update_password($user, $newpassword) {
84 $user = get_complete_user_data('id', $user->id);
85 return update_internal_user_password($user, $newpassword);
88 function prevent_local_passwords() {
89 return false;
92 /**
93 * Returns true if this authentication plugin is 'internal'.
95 * @return bool
97 function is_internal() {
98 return true;
102 * Returns true if this authentication plugin can change the user's
103 * password.
105 * @return bool
107 function can_change_password() {
108 return true;
112 * Returns the URL for changing the user's pw, or empty if the default can
113 * be used.
115 * @return moodle_url
117 function change_password_url() {
118 return null;
122 * Returns true if plugin allows resetting of internal password.
124 * @return bool
126 function can_reset_password() {
127 return true;
131 * Prints a form for configuring this authentication plugin.
133 * This function is called from admin/auth.php, and outputs a full page with
134 * a form for configuring this plugin.
136 * @param array $config An object containing all the data for this page.
137 * @param string $error
138 * @param array $user_fields
139 * @return void
141 function config_form($config, $err, $user_fields) {
142 include 'config.html';
146 * Processes and stores configuration data for this authentication plugin.
148 * @param array $config
149 * @return void
151 function process_config($config) {
152 return true;
156 * Confirm the new user as registered. This should normally not be used,
157 * but it may be necessary if the user auth_method is changed to manual
158 * before the user is confirmed.
160 * @param string $username
161 * @param string $confirmsecret
163 function user_confirm($username, $confirmsecret = null) {
164 global $DB;
166 $user = get_complete_user_data('username', $username);
168 if (!empty($user)) {
169 if ($user->confirmed) {
170 return AUTH_CONFIRM_ALREADY;
171 } else {
172 $DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
173 if ($user->firstaccess == 0) {
174 $DB->set_field("user", "firstaccess", time(), array("id"=>$user->id));
176 return AUTH_CONFIRM_OK;
178 } else {
179 return AUTH_CONFIRM_ERROR;