Merge branch 'MDL-53249-30' of git://github.com/merrill-oakland/moodle into MOODLE_30...
[moodle.git] / auth / nntp / auth.php
blob909d920bda24b742630f83322607058a884be394
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: NNTP Authentication
19 * Authenticates against an NNTP server.
21 * @package auth_nntp
22 * @author Martin Dougiamas
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->libdir.'/authlib.php');
30 /**
31 * NNTP authentication plugin.
33 class auth_plugin_nntp extends auth_plugin_base {
35 /**
36 * Constructor.
38 public function __construct() {
39 $this->authtype = 'nntp';
40 $this->config = get_config('auth/nntp');
43 /**
44 * Old syntax of class constructor for backward compatibility.
46 public function auth_plugin_nntp() {
47 self::__construct();
50 /**
51 * Returns true if the username and password work and false if they are
52 * wrong or don't exist.
54 * @param string $username The username
55 * @param string $password The password
56 * @return bool Authentication success or failure.
58 function user_login ($username, $password) {
59 if (! function_exists('imap_open')) {
60 print_error('auth_nntpnotinstalled','auth_nntp');
61 exit;
64 global $CFG;
66 // try each multiple host
67 $hosts = explode(';', $this->config->host);
68 foreach ($hosts as $host) {
69 $host = '{' . trim($host) . ':' . $this->config->port . '/nntp}';
71 error_reporting(0);
72 $connection = imap_open($host, $username, $password, OP_HALFOPEN);
73 error_reporting($CFG->debug);
75 if ($connection) {
76 imap_close($connection);
77 return true;
80 return false;
83 function prevent_local_passwords() {
84 return true;
87 /**
88 * Returns true if this authentication plugin is 'internal'.
90 * @return bool
92 function is_internal() {
93 return false;
96 /**
97 * Returns true if this authentication plugin can change the user's
98 * password.
100 * @return bool
102 function can_change_password() {
103 return false;
107 * Prints a form for configuring this authentication plugin.
109 * This function is called from admin/auth.php, and outputs a full page with
110 * a form for configuring this plugin.
112 * @param array $page An object containing all the data for this page.
114 function config_form($config, $err, $user_fields) {
115 include "config.html";
119 * Processes and stores configuration data for this authentication plugin.
121 function process_config($config) {
122 // set to defaults if undefined
123 if (!isset ($config->host)) {
124 $config->host = '127.0.0.1';
126 if (!isset ($config->port)) {
127 $config->port = '119';
129 if (!isset($config->changepasswordurl)) {
130 $config->changepasswordurl = '';
133 // save settings
134 set_config('host', $config->host, 'auth/nntp');
135 set_config('port', $config->port, 'auth/nntp');
136 set_config('changepasswordurl', $config->changepasswordurl, 'auth/nntp');
138 return true;