]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/FusionForge.php
var --> public
[SourceForge/phpwiki.git] / lib / WikiUser / FusionForge.php
1 <?php
2
3 /*
4  * Copyright (C) 2006 Alain Peyrat
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 /** Call the FusionForge functions to get the username
24  *
25  */
26 class _FusionForgePassUser extends _PassUser
27 {
28
29     public $_is_external = 0;
30
31     function _FusionForgePassUser($UserName = '', $prefs = false)
32     {
33         if ($prefs) $this->_prefs = $prefs;
34         if (!isset($this->_prefs->_method))
35             _PassUser::_PassUser($UserName);
36         if ($UserName) $this->_userid = $UserName;
37         $this->_authmethod = 'FusionForge';
38
39         // Is this double check really needed?
40         // It is not expensive so we keep it for now.
41         if ($this->userExists())
42             return $this;
43         else
44             return $GLOBALS['ForbiddenUser'];
45     }
46
47     function userExists()
48     {
49         global $group_id;
50
51         // Mapping (PhpWiki vs FusionForge) performed is:
52         //     ANON  for non logged or non member
53         //     USER  for member of the project.
54         //     ADMIN for member having admin rights
55         if (session_loggedin()) {
56
57             // Get project object (if error => ANON)
58             $project = group_get_object($group_id);
59
60             if (!$project || !is_object($project)) {
61                 $this->_level = WIKIAUTH_ANON;
62                 return false;
63             } elseif ($project->isError()) {
64                 $this->_level = WIKIAUTH_ANON;
65                 return false;
66             }
67
68             $member = false;
69             $user = session_get_user();
70             $perm =& $project->getPermission();
71             if (!$perm || !is_object($perm)) {
72                 $this->_level = WIKIAUTH_ANON;
73                 return false;
74             } elseif (!$perm->isError()) {
75                 $member = $perm->isMember();
76             }
77
78             if ($member) {
79                 $this->_userid = $user->getRealName();
80                 $this->_is_external = method_exists($user, 'getIsExternal') && $user->getIsExternal();
81                 if ($perm->isAdmin()) {
82                     $this->_level = WIKIAUTH_ADMIN;
83                 } else {
84                     $this->_level = WIKIAUTH_USER;
85                 }
86                 return $this;
87             }
88         }
89         $this->_level = WIKIAUTH_ANON;
90         return false;
91     }
92
93     function checkPass($submitted_password)
94     {
95         return $this->userExists()
96             ? ($this->isAdmin() ? WIKIAUTH_ADMIN : WIKIAUTH_USER)
97             : WIKIAUTH_ANON;
98     }
99
100     function mayChangePass()
101     {
102         return false;
103     }
104 }
105
106 // Local Variables:
107 // mode: php
108 // tab-width: 8
109 // c-basic-offset: 4
110 // c-hanging-comment-ender-p: nil
111 // indent-tabs-mode: nil
112 // End: