You are here

tokenauth.install in Token authentication 5

Same filename and directory in other branches
  1. 6.2 tokenauth.install
  2. 6 tokenauth.install
  3. 7 tokenauth.install

File

tokenauth.install
View source
<?php

// TODO: postgres
function tokenauth_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {tokenauth_tokens} (\n        uid int(11) NOT NULL,\n        token varchar(50) NOT NULL,\n        PRIMARY KEY  (token),\n        UNIQUE KEY (uid)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
  }

  // give an initial token to all
  $sql = 'SELECT uid FROM {users}';
  $result = db_query($sql);
  while ($row = db_fetch_object($result)) {
    $sql = "INSERT INTO {tokenauth_tokens} (uid, token) VALUES (%d, '%s')";
    db_query($sql, $row->uid, user_password());
  }
}
function tokenauth_uninstall() {
  db_query('DROP TABLE {tokenauth_tokens}');
  variable_del('tokenauth_length');
  variable_del('tokenauth_pages');
  variable_del('tokenauth_reset');
}