1<?php
2/**
3 * DokuWiki Plugin autogallery (Auth Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Tim Siebentaler <tsvamp333@googlemail.com>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class auth_plugin_autogallery extends DokuWiki_Auth_Plugin {
13
14
15    /**
16     * Constructor.
17     */
18    public function __construct() {
19        parent::__construct(); // for compatibility
20
21        // FIXME set capabilities accordingly
22        //$this->cando['addUser']     = false; // can Users be created?
23        //$this->cando['delUser']     = false; // can Users be deleted?
24        //$this->cando['modLogin']    = false; // can login names be changed?
25        //$this->cando['modPass']     = false; // can passwords be changed?
26        //$this->cando['modName']     = false; // can real names be changed?
27        //$this->cando['modMail']     = false; // can emails be changed?
28        //$this->cando['modGroups']   = false; // can groups be changed?
29        //$this->cando['getUsers']    = false; // can a (filtered) list of users be retrieved?
30        //$this->cando['getUserCount']= false; // can the number of users be retrieved?
31        //$this->cando['getGroups']   = false; // can a list of available groups be retrieved?
32        //$this->cando['external']    = false; // does the module do external auth checking?
33        //$this->cando['logout']      = true; // can the user logout again? (eg. not possible with HTTP auth)
34
35        // FIXME intialize your auth system and set success to true, if successful
36        $this->success = true;
37    }
38
39
40    /**
41     * Log off the current user [ OPTIONAL ]
42     */
43    //public function logOff() {
44    //}
45
46    /**
47     * Do all authentication [ OPTIONAL ]
48     *
49     * @param   string  $user    Username
50     * @param   string  $pass    Cleartext Password
51     * @param   bool    $sticky  Cookie should not expire
52     * @return  bool             true on successful auth
53     */
54    //public function trustExternal($user, $pass, $sticky = false) {
55        /* some example:
56
57        global $USERINFO;
58        global $conf;
59        $sticky ? $sticky = true : $sticky = false; //sanity check
60
61        // do the checking here
62
63        // set the globals if authed
64        $USERINFO['name'] = 'FIXME';
65        $USERINFO['mail'] = 'FIXME';
66        $USERINFO['grps'] = array('FIXME');
67        $_SERVER['REMOTE_USER'] = $user;
68        $_SESSION[DOKU_COOKIE]['auth']['user'] = $user;
69        $_SESSION[DOKU_COOKIE]['auth']['pass'] = $pass;
70        $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
71        return true;
72
73        */
74    //}
75
76    /**
77     * Check user+password
78     *
79     * May be ommited if trustExternal is used.
80     *
81     * @param   string $user the user name
82     * @param   string $pass the clear text password
83     * @return  bool
84     */
85    public function checkPass($user, $pass) {
86        // FIXME implement password check
87        return false; // return true if okay
88    }
89
90    /**
91     * Return user info
92     *
93     * Returns info about the given user needs to contain
94     * at least these fields:
95     *
96     * name string  full name of the user
97     * mail string  email addres of the user
98     * grps array   list of groups the user is in
99     *
100     * @param   string $user the user name
101     * @return  array containing user data or false
102     * @param   bool $requireGroups whether or not the returned data must include groups
103     */
104    public function getUserData($user, $requireGroups=true) {
105        // FIXME implement
106        return false;
107    }
108
109    /**
110     * Create a new User [implement only where required/possible]
111     *
112     * Returns false if the user already exists, null when an error
113     * occurred and true if everything went well.
114     *
115     * The new user HAS TO be added to the default group by this
116     * function!
117     *
118     * Set addUser capability when implemented
119     *
120     * @param  string     $user
121     * @param  string     $pass
122     * @param  string     $name
123     * @param  string     $mail
124     * @param  null|array $grps
125     * @return bool|null
126     */
127    //public function createUser($user, $pass, $name, $mail, $grps = null) {
128        // FIXME implement
129    //    return null;
130    //}
131
132    /**
133     * Modify user data [implement only where required/possible]
134     *
135     * Set the mod* capabilities according to the implemented features
136     *
137     * @param   string $user    nick of the user to be changed
138     * @param   array  $changes array of field/value pairs to be changed (password will be clear text)
139     * @return  bool
140     */
141    //public function modifyUser($user, $changes) {
142        // FIXME implement
143    //    return false;
144    //}
145
146    /**
147     * Delete one or more users [implement only where required/possible]
148     *
149     * Set delUser capability when implemented
150     *
151     * @param   array  $users
152     * @return  int    number of users deleted
153     */
154    //public function deleteUsers($users) {
155        // FIXME implement
156    //    return false;
157    //}
158
159    /**
160     * Bulk retrieval of user data [implement only where required/possible]
161     *
162     * Set getUsers capability when implemented
163     *
164     * @param   int   $start     index of first user to be returned
165     * @param   int   $limit     max number of users to be returned, 0 for unlimited
166     * @param   array $filter    array of field/pattern pairs, null for no filter
167     * @return  array list of userinfo (refer getUserData for internal userinfo details)
168     */
169    //public function retrieveUsers($start = 0, $limit = 0, $filter = null) {
170        // FIXME implement
171    //    return array();
172    //}
173
174    /**
175     * Return a count of the number of user which meet $filter criteria
176     * [should be implemented whenever retrieveUsers is implemented]
177     *
178     * Set getUserCount capability when implemented
179     *
180     * @param  array $filter array of field/pattern pairs, empty array for no filter
181     * @return int
182     */
183    //public function getUserCount($filter = array()) {
184        // FIXME implement
185    //    return 0;
186    //}
187
188    /**
189     * Define a group [implement only where required/possible]
190     *
191     * Set addGroup capability when implemented
192     *
193     * @param   string $group
194     * @return  bool
195     */
196    //public function addGroup($group) {
197        // FIXME implement
198    //    return false;
199    //}
200
201    /**
202     * Retrieve groups [implement only where required/possible]
203     *
204     * Set getGroups capability when implemented
205     *
206     * @param   int $start
207     * @param   int $limit
208     * @return  array
209     */
210    //public function retrieveGroups($start = 0, $limit = 0) {
211        // FIXME implement
212    //    return array();
213    //}
214
215    /**
216     * Return case sensitivity of the backend
217     *
218     * When your backend is caseinsensitive (eg. you can login with USER and
219     * user) then you need to overwrite this method and return false
220     *
221     * @return bool
222     */
223    public function isCaseSensitive() {
224        return true;
225    }
226
227    /**
228     * Sanitize a given username
229     *
230     * This function is applied to any user name that is given to
231     * the backend and should also be applied to any user name within
232     * the backend before returning it somewhere.
233     *
234     * This should be used to enforce username restrictions.
235     *
236     * @param string $user username
237     * @return string the cleaned username
238     */
239    public function cleanUser($user) {
240        return $user;
241    }
242
243    /**
244     * Sanitize a given groupname
245     *
246     * This function is applied to any groupname that is given to
247     * the backend and should also be applied to any groupname within
248     * the backend before returning it somewhere.
249     *
250     * This should be used to enforce groupname restrictions.
251     *
252     * Groupnames are to be passed without a leading '@' here.
253     *
254     * @param  string $group groupname
255     * @return string the cleaned groupname
256     */
257    public function cleanGroup($group) {
258        return $group;
259    }
260
261    /**
262     * Check Session Cache validity [implement only where required/possible]
263     *
264     * DokuWiki caches user info in the user's session for the timespan defined
265     * in $conf['auth_security_timeout'].
266     *
267     * This makes sure slow authentication backends do not slow down DokuWiki.
268     * This also means that changes to the user database will not be reflected
269     * on currently logged in users.
270     *
271     * To accommodate for this, the user manager plugin will touch a reference
272     * file whenever a change is submitted. This function compares the filetime
273     * of this reference file with the time stored in the session.
274     *
275     * This reference file mechanism does not reflect changes done directly in
276     * the backend's database through other means than the user manager plugin.
277     *
278     * Fast backends might want to return always false, to force rechecks on
279     * each page load. Others might want to use their own checking here. If
280     * unsure, do not override.
281     *
282     * @param  string $user - The username
283     * @return bool
284     */
285    //public function useSessionCache($user) {
286      // FIXME implement
287    //}
288}
289
290// vim:ts=4:sw=4:et:
291