DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:authpdo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
plugin:authpdo [2018-04-30 16:30]
Aleksandr [Real World Examples]
plugin:authpdo [2018-05-03 19:07] (current)
Aleksandr
Line 22: Line 22:
  
 This plugin allows to configure your wiki to authenticate against an existing database using PHP's PDO extension. Typical use cases are integrating DokuWiki with a web forum, blog or bug tracker. This plugin allows to configure your wiki to authenticate against an existing database using PHP's PDO extension. Typical use cases are integrating DokuWiki with a web forum, blog or bug tracker.
 +
  
 ===== Real World Examples ===== ===== Real World Examples =====
Line 32: Line 33:
   * [[plugin:​authpdo:​Questions2Answers|Questions2Answers]] -- Q&A Forum [[http://​www.question2answer.org/​|question2answer.org]]   * [[plugin:​authpdo:​Questions2Answers|Questions2Answers]] -- Q&A Forum [[http://​www.question2answer.org/​|question2answer.org]]
    
 +
 ===== Configuration ===== ===== Configuration =====
  
 To configure this plugin, some experience with database queries and the SQL query language is required. Sample configurations for popular systems will soon be provided by the community. To configure this plugin, some experience with database queries and the SQL query language is required. Sample configurations for popular systems will soon be provided by the community.
  
-The configuration consists mostly of SQL statements to access your database. The plugin itself is completely database agnostic. You can use it to access any database supported by PDO - refer to [[http://​php.net/​manual/​en/​pdo.drivers.php|PDO Drivers]] to learn more.+The configuration consists mostly of SQL statements to access your database. The plugin itself is completely database agnostic. You can use it to access any database supported by PDO -- refer to [[http://​php.net/​manual/​en/​pdo.drivers.php|PDO Drivers]] to learn more.
  
 In most of the statements named PDO placeholders are used (colon prefixed alphanumeric). These represent the actual data that will be inserted into the statement. The PDO driver takes care of proper escaping - you do not have to worry about it. In most of the statements named PDO placeholders are used (colon prefixed alphanumeric). These represent the actual data that will be inserted into the statement. The PDO driver takes care of proper escaping - you do not have to worry about it.
Line 43: Line 45:
  
 Each option below comes with an example that shows how the statement would look for a fictive [[#example database]] given at the end of this page. Each option below comes with an example that shows how the statement would look for a fictive [[#example database]] given at the end of this page.
 +
  
 ==== General Settings ==== ==== General Settings ====
 +
  
 === Option '​debug'​ === === Option '​debug'​ ===
  
 This setting will output detailed error messages whenever something goes wrong. You most probably want to enable this during the initial configuration of the plugin. Once everything works you should definitely disable this again as it may leak important information to possible attackers. This setting will output detailed error messages whenever something goes wrong. You most probably want to enable this during the initial configuration of the plugin. Once everything works you should definitely disable this again as it may leak important information to possible attackers.
 +
  
 === Option '​dsn'​ === === Option '​dsn'​ ===
Line 66: Line 71:
   * [[http://​php.net/​manual/​en/​ref.pdo-pgsql.connection.php|PDO_PGSQL DSN]]   * [[http://​php.net/​manual/​en/​ref.pdo-pgsql.connection.php|PDO_PGSQL DSN]]
   * [[http://​php.net/​manual/​en/​ref.pdo-sqlite.connection.php|PDO_SQLITE DSN]]   * [[http://​php.net/​manual/​en/​ref.pdo-sqlite.connection.php|PDO_SQLITE DSN]]
 +
  
 === Option '​user'​ === === Option '​user'​ ===
  
 This option configures the user to use to connect to the database. You can leave it empty for sqlite databases. This option configures the user to use to connect to the database. You can leave it empty for sqlite databases.
 +
  
 === Option '​pass'​ === === Option '​pass'​ ===
  
 This is the password for above user. You can leave it empty for sqlite databases. This is the password for above user. You can leave it empty for sqlite databases.
 +
  
 ==== Related Core Settings ==== ==== Related Core Settings ====
Line 88: Line 96:
  
 This plugin gains more capabilities the more of the configuration you fill in. You can leave out configuration at the expense of functionality. However a few statements are required to have minimal login functionality:​ This plugin gains more capabilities the more of the configuration you fill in. You can leave out configuration at the expense of functionality. However a few statements are required to have minimal login functionality:​
 +
  
 === Option '​select-user'​ === === Option '​select-user'​ ===
Line 113: Line 122:
  WHERE "​login"​ = :user  WHERE "​login"​ = :user
 </​code>​ </​code>​
 +
  
 === Option '​select-user-groups'​ === === Option '​select-user-groups'​ ===
Line 133: Line 143:
    AND m."​uid"​ = :uid    AND m."​uid"​ = :uid
 </​code>​ </​code>​
 +
  
 === Option '​check-pass'​ === === Option '​check-pass'​ ===
Line 152: Line 163:
  
 Example: Example:
-<​code ​sql>+<​code ​tsql>
 SELECT uid SELECT uid
   FROM user   FROM user
Line 158: Line 169:
    AND pass = MD5(CONCAT(MD5(user),​ MD5(:​clear)))    AND pass = MD5(CONCAT(MD5(user),​ MD5(:​clear)))
 </​code>​ </​code>​
 +
 +
 ==== Additional SQL Setup ==== ==== Additional SQL Setup ====
  
Line 222: Line 235:
      ​VALUES (:user, :hash, :name, :mail)      ​VALUES (:user, :hash, :name, :mail)
 </​code>​ </​code>​
 +
  
 === Option '​delete-user'​ === === Option '​delete-user'​ ===
Line 236: Line 250:
 DELETE FROM "​user"​ WHERE "​id"​ = :uid DELETE FROM "​user"​ WHERE "​id"​ = :uid
 </​code>​ </​code>​
 +
  
 === Option '​list-users'​ === === Option '​list-users'​ ===
Line 243: Line 258:
 ^ Guaranteed Placeholders ^^ ^ Guaranteed Placeholders ^^
 | '':​user'' ​   | A ''​%''​ wrapped search string to search in logins | | '':​user'' ​   | A ''​%''​ wrapped search string to search in logins |
-| '':​group'' ​   | A ''​%''​ wrapped search string to search in group names  |+| '':​group'' ​  ​| A ''​%''​ wrapped search string to search in group names  |
 | '':​name'' ​   | A ''​%''​ wrapped search string to search in user full names | | '':​name'' ​   | A ''​%''​ wrapped search string to search in user full names |
 | '':​mail'' ​   | A ''​%''​ wrapped search string to search in email addresses ​  | | '':​mail'' ​   | A ''​%''​ wrapped search string to search in email addresses ​  |
-| '':​start'' ​   | The start offset to limit the results ​ | +| '':​start'' ​  ​| The start offset to limit the results ​ | 
-| '':​limit'' ​   | The wanted number of results ​ | +| '':​limit'' ​  ​| The wanted number of results ​ | 
-| '':​end'' ​   | The end offset of wanted results (start+limit) |+| '':​end'' ​    ​| The end offset of wanted results (start+limit) |
 ^ Mandatory fields to return ^^ ^ Mandatory fields to return ^^
 | ''​user'' ​    | The login name | | ''​user'' ​    | The login name |
Line 267: Line 282:
    LIMIT :​start,:​limit    LIMIT :​start,:​limit
 </​code>​ </​code>​
 +
  
 === Option '​count-users'​ === === Option '​count-users'​ ===
Line 274: Line 290:
 ^ Guaranteed Placeholders ^^ ^ Guaranteed Placeholders ^^
 | '':​user'' ​   | A ''​%''​ wrapped search string to search in logins | | '':​user'' ​   | A ''​%''​ wrapped search string to search in logins |
-| '':​group'' ​   | A ''​%''​ wrapped search string to search in group names  |+| '':​group'' ​  ​| A ''​%''​ wrapped search string to search in group names  |
 | '':​name'' ​   | A ''​%''​ wrapped search string to search in user full names | | '':​name'' ​   | A ''​%''​ wrapped search string to search in user full names |
 | '':​mail'' ​   | A ''​%''​ wrapped search string to search in email addresses ​  | | '':​mail'' ​   | A ''​%''​ wrapped search string to search in email addresses ​  |
 ^ Mandatory fields to return ^^ ^ Mandatory fields to return ^^
-| ''​count'' ​    ​| Number of users | +| ''​count'' ​   | Number of users |
  
 <code tsql> <code tsql>
Line 293: Line 308:
    AND U."​mail" ​ LIKE :mail    AND U."​mail" ​ LIKE :mail
 </​code>​ </​code>​
 +
  
 === Option '​update-user-login'​ === === Option '​update-user-login'​ ===
Line 310: Line 326:
  WHERE "​id" ​   = :uid  WHERE "​id" ​   = :uid
 </​code>​ </​code>​
 +
  
 === Option '​update-user-info'​ === === Option '​update-user-info'​ ===
Line 331: Line 348:
  WHERE "​id" ​  = :uid  WHERE "​id" ​  = :uid
 </​code>​ </​code>​
 +
  
 === Option '​update-user-pass'​ === === Option '​update-user-pass'​ ===
Line 350: Line 368:
  WHERE "​id" ​  = :uid  WHERE "​id" ​  = :uid
 </​code>​ </​code>​
 +
  
 === Option '​insert-group'​ === === Option '​insert-group'​ ===
Line 362: Line 381:
      ​VALUES (:group)      ​VALUES (:group)
 </​code>​ </​code>​
 +
  
 === Option '​join-group'​ === === Option '​join-group'​ ===
Line 378: Line 398:
      ​VALUES (:uid, :gid)      ​VALUES (:uid, :gid)
 </​code>​ </​code>​
 +
  
 === Option '​leave-group'​ === === Option '​leave-group'​ ===
Line 394: Line 415:
         AND "​gid"​ = :gid         AND "​gid"​ = :gid
 </​code>​ </​code>​
 +
  
 ===== Example Database ===== ===== Example Database =====
Line 401: Line 423:
 {{ :​plugin:​authpdo-example.png?​280}} {{ :​plugin:​authpdo-example.png?​280}}
  
-<​code ​sql>+<​code ​tsql>
 CREATE TABLE user ( CREATE TABLE user (
     "​id"​ INTEGER PRIMARY KEY AUTOINCREMENT,​     "​id"​ INTEGER PRIMARY KEY AUTOINCREMENT,​
Line 419: Line 441:
 ); );
 </​code>​ </​code>​
 +
  
 ===== A Warning on MySQL MyISAM ===== ===== A Warning on MySQL MyISAM =====
plugin/authpdo.txt · Last modified: 2018-05-03 19:07 by Aleksandr