]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/IMAP.php
Reformat code
[SourceForge/phpwiki.git] / lib / WikiUser / IMAP.php
1 <?php
2
3 /*
4  * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 class _IMAPPassUser
24     extends _PassUser
25     /**
26      * Define the var IMAP_AUTH_HOST in config/config.ini (with port probably)
27      *
28      * Preferences are handled in _PassUser
29      */
30 {
31     function checkPass($submitted_password)
32     {
33         if (!$this->isValidName()) {
34             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::checkPass => failed isValidName", E_USER_WARNING);
35             trigger_error(_("Invalid username."), E_USER_WARNING);
36             return $this->_tryNextPass($submitted_password);
37         }
38         if (!$this->_checkPassLength($submitted_password)) {
39             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::checkPass => failed checkPassLength", E_USER_WARNING);
40             return WIKIAUTH_FORBIDDEN;
41         }
42         $userid = $this->_userid;
43         $mbox = @imap_open("{" . IMAP_AUTH_HOST . "}",
44             $userid, $submitted_password, OP_HALFOPEN);
45         if ($mbox) {
46             imap_close($mbox);
47             $this->_authmethod = 'IMAP';
48             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::checkPass => ok", E_USER_WARNING);
49             $this->_level = WIKIAUTH_USER;
50             return $this->_level;
51         } else {
52             if ($submitted_password != "") { // if LENGTH 0 is allowed
53                 trigger_error(_("Unable to connect to IMAP server ") . IMAP_AUTH_HOST,
54                     E_USER_WARNING);
55             }
56         }
57         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::checkPass => wrong", E_USER_WARNING);
58
59         return $this->_tryNextPass($submitted_password);
60     }
61
62     //CHECKME: this will not be okay for the auth policy strict
63     function userExists()
64     {
65         return true;
66
67         if ($this->checkPass($this->_prefs->get('passwd'))) {
68             if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::userExists => true (pass ok)", E_USER_WARNING);
69             return true;
70         }
71         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::userExists => false (pass wrong)", E_USER_WARNING);
72         return $this->_tryNextUser();
73     }
74
75     function mayChangePass()
76     {
77         if (DEBUG & _DEBUG_LOGIN) trigger_error(get_class($this) . "::mayChangePass => false", E_USER_WARNING);
78         return false;
79     }
80 }
81
82 // Local Variables:
83 // mode: php
84 // tab-width: 8
85 // c-basic-offset: 4
86 // c-hanging-comment-ender-p: nil
87 // indent-tabs-mode: nil
88 // End: