]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/GForge.php
rcs_id no longer makes sense with Subversion global version number
[SourceForge/phpwiki.git] / lib / WikiUser / GForge.php
1 <?php //-*-php-*-
2 // rcs_id('$Id$');
3 /* Copyright (C) 2006 Alain Peyrat
4  * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
5  */
6
7 /** Call the gforge functions to get the username
8  *
9  */
10 class _GForgePassUser extends _PassUser {
11
12     var $_is_external = 0;
13
14     function _GForgePassUser($UserName='',$prefs=false) {
15         if ($prefs) $this->_prefs = $prefs;
16         if (!isset($this->_prefs->_method))
17            _PassUser::_PassUser($UserName);
18         if ($UserName) $this->_userid = $UserName;
19         $this->_authmethod = 'GForge';
20
21         // Is this double check really needed?
22         // It is not expensive so we keep it for now.
23         if ($this->userExists())
24             return $this;
25         else
26             return $GLOBALS['ForbiddenUser'];
27     }
28
29     function userExists() {
30             global $group_id;
31
32         // Mapping (phpWiki vs GForge) performed is:
33         //     ANON  for non logged or non member
34         //     USER  for member of the project.
35         //     ADMIN for member having admin rights
36         if (session_loggedin()){
37
38             // Get project object (if error => ANON)
39             $project =& group_get_object($group_id);
40
41             if (!$project || !is_object($project)) {
42                 $this->_level = WIKIAUTH_ANON;
43                 return false;
44             } elseif ($project->isError()) {
45                 $this->_level = WIKIAUTH_ANON;
46                 return false;
47             }
48
49             $member = false ;
50             $user = session_get_user();
51             $perm =& $project->getPermission($user);
52             if (!$perm || !is_object($perm)) {
53                 $this->_level = WIKIAUTH_ANON;
54                 return false;
55             } elseif (!$perm->isError()) {
56                 $member = $perm->isMember();
57             }
58
59             if ($member) {
60                 $this->_userid = $user->getRealName();
61                 $this->_is_external = $user->getIsExternal();
62                 if ($perm->isAdmin()) {
63                     $this->_level = WIKIAUTH_ADMIN;
64                 } else {
65                     $this->_level = WIKIAUTH_USER;
66                 }
67                 return $this;
68             }
69         }
70                $this->_level = WIKIAUTH_ANON;
71                return false;
72     }
73
74     function checkPass($submitted_password) {
75         return $this->userExists()
76             ? ($this->isAdmin() ? WIKIAUTH_ADMIN : WIKIAUTH_USER)
77             : WIKIAUTH_ANON;
78     }
79
80     function mayChangePass() {
81         return false;
82     }
83 }
84
85 // Local Variables:
86 // mode: php
87 // tab-width: 8
88 // c-basic-offset: 4
89 // c-hanging-comment-ender-p: nil
90 // indent-tabs-mode: nil
91 // End:
92 ?>