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');
22 * NNTP authentication plugin.
24 class auth_plugin_nntp
extends auth_plugin_base
{
29 function auth_plugin_nntp() {
30 $this->authtype
= 'nntp';
31 $this->config
= get_config('auth/nntp');
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');
50 // try each multiple host
51 $hosts = split(';', $this->config
->host
);
52 foreach ($hosts as $host) {
53 $host = '{' . trim($host) . ':' . $this->config
->port
. '/nntp}';
56 $connection = imap_open($host, stripslashes($username), stripslashes($password), OP_HALFOPEN
);
57 error_reporting($CFG->debug
);
60 imap_close($connection);
68 * Returns true if this authentication plugin is 'internal'.
72 function is_internal() {
77 * Returns true if this authentication plugin can change the user's
82 function can_change_password() {
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";
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
= '';
114 set_config('host', $config->host
, 'auth/nntp');
115 set_config('port', $config->port
, 'auth/nntp');
116 set_config('changepasswordurl', $config->changepasswordurl
, 'auth/nntp');