diff options
author | Florian Pritz <bluewind@xinu.at> | 2013-09-25 15:03:59 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2013-09-25 15:03:59 +0200 |
commit | 6705e6c987b6e4a43bbb666c33d8fc8a0ef1a0a6 (patch) | |
tree | b815871f7f031633c400a33cf5d6245282d59955 /application/libraries/Duser | |
parent | 50230001eb5387b6b0ff7ce906d074ef4a530d11 (diff) | |
parent | ab98249a9a087745b29e5cb258ea0b624f12f64b (diff) |
Merge branch 'working'
Diffstat (limited to 'application/libraries/Duser')
-rw-r--r-- | application/libraries/Duser/Duser.php | 33 | ||||
-rw-r--r-- | application/libraries/Duser/drivers/Duser_db.php | 12 | ||||
-rw-r--r-- | application/libraries/Duser/drivers/Duser_fluxbb.php | 53 |
3 files changed, 78 insertions, 20 deletions
diff --git a/application/libraries/Duser/Duser.php b/application/libraries/Duser/Duser.php index 96d61e3cc..07a16190c 100644 --- a/application/libraries/Duser/Duser.php +++ b/application/libraries/Duser/Duser.php @@ -9,14 +9,11 @@ abstract class Duser_Driver extends CI_Driver { - // List of optional functions or function groups that are implemented + // List of optional functions that are implemented // - // Possible values are names of functions already implemented in this - // abstract class or the function groups listed below. - // - // Possible function groups are: - // - can_register_new_users - // - can_reset_password + // Possible values are: + // - can_register_new_users (only supported with the DB driver!) + // - can_reset_password (only supported with the DB driver!) public $optional_functions = array(); /* @@ -24,12 +21,26 @@ abstract class Duser_Driver extends CI_Driver { * - username string * - userid INT > 0 * + * @param username + * @param password * @return mixed array on success, false on failure */ abstract public function login($username, $password); + /* + * @param username + * @return boolean true is username exists, false otherwise + */ public function username_exists($username) { - return false; + return null; + } + + /* + * @param userid + * @return string email address of the user + */ + public function get_email($userid) { + return null; } } @@ -38,7 +49,7 @@ class Duser extends CI_Driver_Library { protected $_adapter = null; protected $valid_drivers = array( - 'duser_db', 'duser_ldap' + 'duser_db', 'duser_ldap', 'duser_fluxbb' ); function __construct() @@ -87,8 +98,6 @@ class Duser extends CI_Driver_Library { public function username_exists($username) { - $this->require_implemented(__FUNCTION__); - if ($username === false) { return false; } @@ -98,8 +107,6 @@ class Duser extends CI_Driver_Library { public function get_email($userid) { - $this->require_implemented(__FUNCTION__); - return $this->{$this->_adapter}->get_email($userid); } } diff --git a/application/libraries/Duser/drivers/Duser_db.php b/application/libraries/Duser/drivers/Duser_db.php index 1258ec585..a58b5a298 100644 --- a/application/libraries/Duser/drivers/Duser_db.php +++ b/application/libraries/Duser/drivers/Duser_db.php @@ -9,11 +9,13 @@ class Duser_db extends Duser_Driver { + /* FIXME: If you use this driver as a template, remove can_reset_password + * and can_register_new_users. These features require the DB driver and + * will NOT work with other drivers. + */ public $optional_functions = array( - 'username_exists', 'can_reset_password', 'can_register_new_users', - 'get_email', ); public function login($username, $password) @@ -26,11 +28,7 @@ class Duser_db extends Duser_Driver { WHERE `username` = ? ', array($username))->row_array(); - if (!isset($query["username"]) || $query["username"] !== $username) { - return false; - } - - if (!isset($query["password"])) { + if (empty($query)) { return false; } diff --git a/application/libraries/Duser/drivers/Duser_fluxbb.php b/application/libraries/Duser/drivers/Duser_fluxbb.php new file mode 100644 index 000000000..1790e830b --- /dev/null +++ b/application/libraries/Duser/drivers/Duser_fluxbb.php @@ -0,0 +1,53 @@ +<?php +/* + * Copyright 2013 Pierre Schmitz <pierre@archlinux.de> + * + * Licensed under AGPLv3 + * (see COPYING for full license text) + * + */ + +class Duser_fluxbb extends Duser_Driver { + + private $CI = null; + private $config = array(); + + function __construct() + { + $this->CI =& get_instance(); + $this->config = $this->CI->config->item('auth_fluxbb'); + } + + public function login($username, $password) + { + $query = $this->CI->db->query(' + SELECT username, id + FROM '.$this->config['database'].'.users + WHERE username = ? AND password = ? + ', array($username, sha1($password)))->row_array(); + + if (!empty($query)) { + return array( + 'username' => $query['username'], + 'userid' => $query['id'] + ); + } else { + return false; + } + } + + public function username_exists($username) + { + $query = $this->CI->db->query(' + SELECT id + FROM '.$this->config['database'].'.users + WHERE username = ? + ', array($username)); + + if ($query->num_rows() > 0) { + return true; + } else { + return false; + } + } +} |