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