Lines Matching +full:update +full:- +full:user +full:- +full:login -(+path:inc +path:lang) -(+path:lib +path:plugins +path:lang) -(+path:lib +path:tpl +path:dokuwiki +path:lang)

10  * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
33 $this->debugMsg('PDO extension for PHP not found.', -1, __LINE__);
34 $this->success = false;
38 if (!$this->getConf('dsn')) {
39 $this->debugMsg('No DSN specified', -1, __LINE__);
40 $this->success = false;
45 $this->pdo = new PDO(
46 $this->getConf('dsn'),
47 $this->getConf('user'),
48 conf_decodeString($this->getConf('pass')),
56 $this->debugMsg($e);
57 msg($this->getLang('connectfail'), -1);
58 $this->success = false;
63 $this->cando['addUser'] = $this->checkConfig(
64 ['select-user', 'select-user-groups', 'select-groups', 'insert-user', 'insert-group', 'join-group']
68 $this->cando['delUser'] = $this->checkConfig(
69 ['select-user', 'select-user-groups', 'select-groups', 'leave-group', 'delete-user']
72 // can login names be changed?
73 $this->cando['modLogin'] = $this->checkConfig(
74 ['select-user', 'select-user-groups', 'update-user-login']
78 $this->cando['modPass'] = $this->checkConfig(
79 ['select-user', 'select-user-groups', 'update-user-pass']
83 $this->cando['modName'] = $this->checkConfig(
84 ['select-user', 'select-user-groups', 'update-user-info:name']
88 $this->cando['modMail'] = $this->checkConfig(
89 ['select-user', 'select-user-groups', 'update-user-info:mail']
93 $this->cando['modGroups'] = $this->checkConfig(
94 ['select-user', 'select-user-groups', 'select-groups', 'leave-group', 'join-group', 'insert-group']
98 $this->cando['getUsers'] = $this->checkConfig(
99 ['list-users']
103 $this->cando['getUserCount'] = $this->checkConfig(
104 ['count-users']
108 $this->cando['getGroups'] = $this->checkConfig(
109 ['select-groups']
112 $this->success = true;
116 * Check user+password
118 * @param string $user the user name
122 public function checkPass($user, $pass)
125 $userdata = $this->selectUser($user);
129 if ($this->checkConfig(['check-pass'])) {
132 $result = $this->query($this->getConf('check-pass'), $userdata);
141 return $passhash->verify_hash($pass, $userdata['hash']);
149 * Return user info
151 * Returns info about the given user needs to contain
154 * name string full name of the user
155 * mail string email addres of the user
156 * grps array list of groups the user is in
158 * @param string $user the user name
160 * @return array|bool containing user data or false
162 public function getUserData($user, $requireGroups = true)
164 $data = $this->selectUser($user);
171 $data['grps'] = $this->selectUserGroups($data);
179 * Create a new User [implement only where required/possible]
181 * Returns false if the user already exists, null when an error
184 * The new user HAS TO be added to the default group by this
189 * @param string $user
196 public function createUser($user, $clear, $name, $mail, $grps = null)
200 if (($info = $this->getUserData($user, false)) !== false) {
201 msg($this->getLang('userexists'), -1);
202 return false; // user already exists
210 $userdata = ['user' => $user, 'clear' => $clear, 'hash' => $hash, 'name' => $name, 'mail' => $mail];
213 $this->pdo->beginTransaction();
215 // insert the user
216 $ok = $this->query($this->getConf('insert-user'), $userdata);
218 $userdata = $this->getUserData($user, false);
222 $allgroups = $this->selectGroups();
225 $ok = $this->addGroup($group);
229 $allgroups = $this->selectGroups();
231 // add user to the groups
233 $ok = $this->joinGroup($userdata, $allgroups[$group]);
237 $this->pdo->commit();
242 $this->pdo->rollBack();
243 $this->debugMsg('Transaction rolled back', 0, __LINE__);
244 msg($this->getLang('writefail'), -1);
249 * Modify user data
251 * @param string $user nick of the user to be changed
255 public function modifyUser($user, $changes)
258 $this->pdo->beginTransaction();
260 $olddata = $this->getUserData($user);
264 // changing the user name?
265 if (isset($changes['user'])) {
266 if ($this->getUserData($changes['user'], false)) goto FAIL;
268 $params['newlogin'] = $changes['user'];
270 $ok = $this->query($this->getConf('update-user-login'), $params);
280 $ok = $this->query($this->getConf('update-user-pass'), $params);
290 $ok = $this->query($this->getConf('update-user-info'), $params);
296 $allgroups = $this->selectGroups();
301 $ok = $this->leaveGroup($olddata, $allgroups[$group]);
310 $ok = $this->addGroup($group);
316 if ($added > 0) $allgroups = $this->selectGroups();
321 $ok = $this->joinGroup($olddata, $allgroups[$group]);
328 $this->pdo->commit();
333 $this->pdo->rollBack();
334 $this->debugMsg('Transaction rolled back', 0, __LINE__);
335 msg($this->getLang('writefail'), -1);
350 foreach ($users as $user) {
351 if ($this->deleteUser($user)) $count++;
357 * Bulk retrieval of user data [implement only where required/possible]
361 * @param int $start index of first user to be returned
366 public function retrieveUsers($start = 0, $limit = -1, $filter = null)
372 foreach (['user', 'name', 'mail', 'group'] as $key) {
383 $result = $this->query($this->getConf('list-users'), $filter);
388 if (!isset($row['user'])) {
389 $this->debugMsg("list-users statement did not return 'user' attribute", -1, __LINE__);
392 $users[] = $this->getUserData($row['user']);
395 $this->debugMsg("list-users statement did not return a list of result", -1, __LINE__);
401 * Return a count of the number of user which meet $filter criteria
411 foreach (['user', 'name', 'mail', 'group'] as $key) {
419 $result = $this->query($this->getConf('count-users'), $filter);
421 $this->debugMsg("Statement did not return 'count' attribute", -1, __LINE__);
434 $sql = $this->getConf('insert-group');
436 $result = $this->query($sql, [':group' => $group]);
437 $this->clearGroupCache();
453 $groups = array_keys($this->selectGroups());
464 * Select data of a specified user
466 * @param string $user the user name
467 * @return bool|array user data, false on error
469 protected function selectUser($user)
471 $sql = $this->getConf('select-user');
473 $result = $this->query($sql, [':user' => $user]);
477 $this->debugMsg('Found more than one matching user', -1, __LINE__);
484 if (!isset($data['user'])) {
485 $this->debugMsg("Statement did not return 'user' attribute", -1, __LINE__);
488 if (!isset($data['hash']) && !isset($data['clear']) && !$this->checkConfig(['check-pass'])) {
489 $this->debugMsg("Statement did not return 'clear' or 'hash' attribute", -1, __LINE__);
493 $this->debugMsg("Statement did not return 'name' attribute", -1, __LINE__);
497 $this->debugMsg("Statement did not return 'mail' attribute", -1, __LINE__);
506 * Delete a user after removing all their group memberships
508 * @param string $user
509 * @return bool true when the user was deleted
511 protected function deleteUser($user)
513 $this->pdo->beginTransaction();
515 $userdata = $this->getUserData($user);
517 $allgroups = $this->selectGroups();
522 $this->leaveGroup($userdata, $allgroups[$group]);
526 $ok = $this->query($this->getConf('delete-user'), $userdata);
529 $this->pdo->commit();
533 $this->pdo->rollBack();
538 * Select all groups of a user
546 $sql = $this->getConf('select-user-groups');
547 $result = $this->query($sql, $userdata);
554 $this->debugMsg("No 'group' field returned in select-user-groups statement", -1, __LINE__);
560 $this->debugMsg("select-user-groups statement did not return a list of result", -1, __LINE__);
575 if ($this->groupcache) return $this->groupcache;
577 $sql = $this->getConf('select-groups');
578 $result = $this->query($sql);
585 $this->debugMsg("No 'group' field returned from select-groups statement", -1, __LINE__);
594 $this->debugMsg("select-groups statement did not return a list of result", -1, __LINE__);
606 $this->groupcache = null;
610 * Adds the user to the group
612 * @param array $userdata all the user data
619 $sql = $this->getConf('join-group');
620 $result = $this->query($sql, $data);
626 * Removes the user from the group
628 * @param array $userdata all the user data
635 $sql = $this->getConf('leave-group');
636 $result = $this->query($sql, $data);
652 $this->debugMsg('No SQL query given', -1, __LINE__);
658 $sth = $this->pdo->prepare($sql);
661 // prepare parameters - we only use those that exist in the SQL
669 $sth->bindValue($key, $value, PDO::PARAM_INT);
671 $sth->bindValue($key, $value);
676 $sth->execute();
682 $result = $sth->fetchAll();
684 $result = $sth->rowCount();
691 $hasnextrowset = $sth->nextRowset(); // run next rowset
693 $hasnextrowset = false; // driver does not support multi-rowset, should be executed in one time
700 $dsql = $this->debugSQL($sql, $params, !defined('DOKU_UNITTEST'));
701 $this->debugMsg($e, -1, $line);
702 $this->debugMsg("SQL: <pre>$dsql</pre>", -1, $line);
704 $sth->closeCursor();
718 if (!$this->getConf('debug')) return;
720 $err = -1;
721 $msg = $message->getMessage();
722 if (!$line) $line = $message->getLine();
747 $sql = trim($this->getConf($key));
772 $val = $this->pdo->quote($val, PDO::PARAM_INT);
774 $val = $this->pdo->quote($val, PDO::PARAM_BOOL);
778 $val = $this->pdo->quote($val);