Merge branch 'MDL-25881' of git://git.luns.net.uk/moodle
[moodle.git] / auth / webservice / auth.php
CommitLineData
44bce9b4 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Web service auth plugin, reserves username, prevents normal login.
20 * TODO: add IP restrictions and some other features - MDL-17135
21 *
22 * @package moodlecore
23 * @subpackage webservice
24 * @copyright 2008 Petr Skoda (http://skodak.org)
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27
28if (!defined('MOODLE_INTERNAL')) {
29 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
30}
31
32require_once($CFG->libdir.'/authlib.php');
33
34/**
35 * Web service auth plugin.
36 */
37class auth_plugin_webservice extends auth_plugin_base {
38
39 /**
40 * Constructor.
41 */
42 function auth_plugin_webservice() {
43 $this->authtype = 'webservice';
44 $this->config = get_config('auth/webservice');
45 }
46
47 /**
48 * Returns true if the username and password work and false if they are
49 * wrong or don't exist.
50 *
51 * @param string $username The username (with system magic quotes)
52 * @param string $password The password (with system magic quotes)
53 *
54 * @return bool Authentication success or failure.
55 */
56 function user_login($username, $password) {
57 // normla logins not allowed!
58 return false;
59 }
60
61 /**
62 * Custom auth hook for web services.
63 * @param string $username
64 * @param string $password
65 * @return bool success
66 */
67 function user_login_webservice($username, $password) {
68 global $CFG, $DB;
69 // special web service login
70 if ($user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
71 return validate_internal_user_password($user, $password);
72 }
73 return false;
74 }
75
76 /**
77 * Updates the user's password.
78 *
79 * called when the user password is updated.
80 *
81 * @param object $user User table object (with system magic quotes)
82 * @param string $newpassword Plaintext password (with system magic quotes)
83 * @return boolean result
84 *
85 */
86 function user_update_password($user, $newpassword) {
87 $user = get_complete_user_data('id', $user->id);
88 return update_internal_user_password($user, $newpassword);
89 }
90
91 /**
92 * Returns true if this authentication plugin is 'internal'.
93 *
94 * @return bool
95 */
96 function is_internal() {
97 return true;
98 }
99
100 /**
101 * Returns true if this authentication plugin can change the user's
102 * password.
103 *
104 * @return bool
105 */
106 function can_change_password() {
107 return false;
108 }
109
110 /**
111 * Returns the URL for changing the user's pw, or empty if the default can
112 * be used.
113 *
99f9f85f 114 * @return moodle_url
44bce9b4 115 */
116 function change_password_url() {
99f9f85f 117 return null;
44bce9b4 118 }
119
120 /**
121 * Returns true if plugin allows resetting of internal password.
122 *
123 * @return bool
124 */
125 function can_reset_password() {
126 return false;
127 }
128
129 /**
130 * Prints a form for configuring this authentication plugin.
131 *
132 * This function is called from admin/auth.php, and outputs a full page with
133 * a form for configuring this plugin.
134 *
135 * @param array $page An object containing all the data for this page.
136 */
137 function config_form($config, $err, $user_fields) {
138 }
139
140 /**
141 * Processes and stores configuration data for this authentication plugin.
142 */
143 function process_config($config) {
144 return true;
145 }
146
147 /**
148 * Confirm the new user as registered. This should normally not be used,
5117d598 149 * but it may be necessary if the user auth_method is changed to manual
44bce9b4 150 * before the user is confirmed.
151 */
152 function user_confirm($username, $confirmsecret = null) {
5117d598 153 return AUTH_CONFIRM_ERROR;
44bce9b4 154 }
155
156}