xref: /plugin/authwordpress/auth.php (revision 24cd6f552c774a11ea81a085f6f07977afaf4cd4)
1<?php
2/**
3 * DokuWiki Plugin authwordpress (Auth Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Damien Regad <dregad@mantisbt.org>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class auth_plugin_authwordpress 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     */
103    public function getUserData($user) {
104        // FIXME implement
105        return false;
106    }
107
108    /**
109     * Create a new User [implement only where required/possible]
110     *
111     * Returns false if the user already exists, null when an error
112     * occurred and true if everything went well.
113     *
114     * The new user HAS TO be added to the default group by this
115     * function!
116     *
117     * Set addUser capability when implemented
118     *
119     * @param  string     $user
120     * @param  string     $pass
121     * @param  string     $name
122     * @param  string     $mail
123     * @param  null|array $grps
124     * @return bool|null
125     */
126    //public function createUser($user, $pass, $name, $mail, $grps = null) {
127        // FIXME implement
128    //    return null;
129    //}
130
131    /**
132     * Modify user data [implement only where required/possible]
133     *
134     * Set the mod* capabilities according to the implemented features
135     *
136     * @param   string $user    nick of the user to be changed
137     * @param   array  $changes array of field/value pairs to be changed (password will be clear text)
138     * @return  bool
139     */
140    //public function modifyUser($user, $changes) {
141        // FIXME implement
142    //    return false;
143    //}
144
145    /**
146     * Delete one or more users [implement only where required/possible]
147     *
148     * Set delUser capability when implemented
149     *
150     * @param   array  $users
151     * @return  int    number of users deleted
152     */
153    //public function deleteUsers($users) {
154        // FIXME implement
155    //    return false;
156    //}
157
158    /**
159     * Bulk retrieval of user data [implement only where required/possible]
160     *
161     * Set getUsers capability when implemented
162     *
163     * @param   int   $start     index of first user to be returned
164     * @param   int   $limit     max number of users to be returned
165     * @param   array $filter    array of field/pattern pairs, null for no filter
166     * @return  array list of userinfo (refer getUserData for internal userinfo details)
167     */
168    //public function retrieveUsers($start = 0, $limit = -1, $filter = null) {
169        // FIXME implement
170    //    return array();
171    //}
172
173    /**
174     * Return a count of the number of user which meet $filter criteria
175     * [should be implemented whenever retrieveUsers is implemented]
176     *
177     * Set getUserCount capability when implemented
178     *
179     * @param  array $filter array of field/pattern pairs, empty array for no filter
180     * @return int
181     */
182    //public function getUserCount($filter = array()) {
183        // FIXME implement
184    //    return 0;
185    //}
186
187    /**
188     * Define a group [implement only where required/possible]
189     *
190     * Set addGroup capability when implemented
191     *
192     * @param   string $group
193     * @return  bool
194     */
195    //public function addGroup($group) {
196        // FIXME implement
197    //    return false;
198    //}
199
200    /**
201     * Retrieve groups [implement only where required/possible]
202     *
203     * Set getGroups capability when implemented
204     *
205     * @param   int $start
206     * @param   int $limit
207     * @return  array
208     */
209    //public function retrieveGroups($start = 0, $limit = 0) {
210        // FIXME implement
211    //    return array();
212    //}
213
214    /**
215     * Return case sensitivity of the backend
216     *
217     * When your backend is caseinsensitive (eg. you can login with USER and
218     * user) then you need to overwrite this method and return false
219     *
220     * @return bool
221     */
222    public function isCaseSensitive() {
223        return true;
224    }
225
226    /**
227     * Sanitize a given username
228     *
229     * This function is applied to any user name that is given to
230     * the backend and should also be applied to any user name within
231     * the backend before returning it somewhere.
232     *
233     * This should be used to enforce username restrictions.
234     *
235     * @param string $user username
236     * @return string the cleaned username
237     */
238    public function cleanUser($user) {
239        return $user;
240    }
241
242    /**
243     * Sanitize a given groupname
244     *
245     * This function is applied to any groupname that is given to
246     * the backend and should also be applied to any groupname within
247     * the backend before returning it somewhere.
248     *
249     * This should be used to enforce groupname restrictions.
250     *
251     * Groupnames are to be passed without a leading '@' here.
252     *
253     * @param  string $group groupname
254     * @return string the cleaned groupname
255     */
256    public function cleanGroup($group) {
257        return $group;
258    }
259
260    /**
261     * Check Session Cache validity [implement only where required/possible]
262     *
263     * DokuWiki caches user info in the user's session for the timespan defined
264     * in $conf['auth_security_timeout'].
265     *
266     * This makes sure slow authentication backends do not slow down DokuWiki.
267     * This also means that changes to the user database will not be reflected
268     * on currently logged in users.
269     *
270     * To accommodate for this, the user manager plugin will touch a reference
271     * file whenever a change is submitted. This function compares the filetime
272     * of this reference file with the time stored in the session.
273     *
274     * This reference file mechanism does not reflect changes done directly in
275     * the backend's database through other means than the user manager plugin.
276     *
277     * Fast backends might want to return always false, to force rechecks on
278     * each page load. Others might want to use their own checking here. If
279     * unsure, do not override.
280     *
281     * @param  string $user - The username
282     * @return bool
283     */
284    //public function useSessionCache($user) {
285      // FIXME implement
286    //}
287}
288
289// vim:ts=4:sw=4:et: