Fixes bug MDL-8234, "New groups code & AS keyword"
[moodle-pu.git] / auth / nntp / auth.php
blob39ef4756885aff738fa8640d0bd1de2ff8ccedf3
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 // This page cannot be called directly
16 if (!isset($CFG)) exit;
18 /**
19 * NNTP authentication plugin.
21 class auth_plugin_nntp {
23 /**
24 * The configuration details for the plugin.
26 var $config;
28 /**
29 * Constructor.
31 function auth_plugin_nntp() {
32 $this->config = get_config('auth/nntp');
35 /**
36 * Returns true if the username and password work and false if they are
37 * wrong or don't exist.
39 * @param string $username The username
40 * @param string $password The password
41 * @returns bool Authentication success or failure.
43 function user_login ($username, $password) {
44 if (! function_exists('imap_open')) {
45 print_error('auth_nntpnotinstalled','auth');
46 exit;
49 global $CFG;
51 // try each multiple host
52 $hosts = split(';', $this->config->host);
53 foreach ($hosts as $host) {
54 $host = '{' . trim($host) . ':' . $this->config->port . '/nntp}';
56 error_reporting(0);
57 $connection = imap_open($host, $username, $password, OP_HALFOPEN);
58 error_reporting($CFG->debug);
60 if ($connection) {
61 imap_close($connection);
62 return true;
65 return false;
68 /**
69 * Returns true if this authentication plugin is 'internal'.
71 * @returns bool
73 function is_internal() {
74 return false;
77 /**
78 * Returns true if this authentication plugin can change the user's
79 * password.
81 * @returns bool
83 function can_change_password() {
84 return false;
87 /**
88 * Prints a form for configuring this authentication plugin.
90 * This function is called from admin/auth.php, and outputs a full page with
91 * a form for configuring this plugin.
93 * @param array $page An object containing all the data for this page.
95 function config_form($config, $err) {
96 include "config.html";
99 /**
100 * Processes and stores configuration data for this authentication plugin.
102 function process_config($config) {
103 // set to defaults if undefined
104 if (!isset ($config->host)) {
105 $config->host = '127.0.0.1';
107 if (!isset ($config->port)) {
108 $config->port = '119';
110 if (!isset($config->changepasswordurl)) {
111 $config->changepasswordurl = '';
114 // save settings
115 set_config('host', $config->host, 'auth/nntp');
116 set_config('port', $config->port, 'auth/nntp');
117 set_config('changepasswordurl', $config->changepasswordurl, 'auth/nntp');
119 return true;