MDL-10910 Corrected two errors committed while fixing MDL-10870
[moodle-pu.git] / auth / nntp / auth.php
blobda549b915ea8c8ac79ba448ba76e6ee1ec2e8352
1 <?php
3 /**
4 * @author Martin Dougiamas
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package moodle multiauth
8 * Authentication Plugin: NNTP Authentication
10 * Authenticates against an NNTP server.
12 * 2006-08-31 File created.
15 if (!defined('MOODLE_INTERNAL')) {
16 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
19 require_once($CFG->libdir.'/authlib.php');
21 /**
22 * NNTP authentication plugin.
24 class auth_plugin_nntp extends auth_plugin_base {
26 /**
27 * Constructor.
29 function auth_plugin_nntp() {
30 $this->authtype = 'nntp';
31 $this->config = get_config('auth/nntp');
34 /**
35 * Returns true if the username and password work and false if they are
36 * wrong or don't exist.
38 * @param string $username The username (with system magic quotes)
39 * @param string $password The password (with system magic quotes)
40 * @return bool Authentication success or failure.
42 function user_login ($username, $password) {
43 if (! function_exists('imap_open')) {
44 print_error('auth_nntpnotinstalled','auth');
45 exit;
48 global $CFG;
50 // try each multiple host
51 $hosts = split(';', $this->config->host);
52 foreach ($hosts as $host) {
53 $host = '{' . trim($host) . ':' . $this->config->port . '/nntp}';
55 error_reporting(0);
56 $connection = imap_open($host, stripslashes($username), stripslashes($password), OP_HALFOPEN);
57 error_reporting($CFG->debug);
59 if ($connection) {
60 imap_close($connection);
61 return true;
64 return false;
67 /**
68 * Returns true if this authentication plugin is 'internal'.
70 * @return bool
72 function is_internal() {
73 return false;
76 /**
77 * Returns true if this authentication plugin can change the user's
78 * password.
80 * @return bool
82 function can_change_password() {
83 return false;
86 /**
87 * Prints a form for configuring this authentication plugin.
89 * This function is called from admin/auth.php, and outputs a full page with
90 * a form for configuring this plugin.
92 * @param array $page An object containing all the data for this page.
94 function config_form($config, $err, $user_fields) {
95 include "config.html";
98 /**
99 * Processes and stores configuration data for this authentication plugin.
101 function process_config($config) {
102 // set to defaults if undefined
103 if (!isset ($config->host)) {
104 $config->host = '127.0.0.1';
106 if (!isset ($config->port)) {
107 $config->port = '119';
109 if (!isset($config->changepasswordurl)) {
110 $config->changepasswordurl = '';
113 // save settings
114 set_config('host', $config->host, 'auth/nntp');
115 set_config('port', $config->port, 'auth/nntp');
116 set_config('changepasswordurl', $config->changepasswordurl, 'auth/nntp');
118 return true;