Permalink
Browse files

Compatibility changes & some extras.

  • Loading branch information...
1 parent d89ade7 commit 7eb6cc2a587a7d9660cf058af7982575e6d769d7 @adamgriffiths committed Aug 24, 2011
View
@@ -1,66 +0,0 @@
-<?php
-/**
-* Authentication Library
-*
-* @package Authentication
-* @category Libraries
-* @author Adam Griffiths
-* @link http://adamgriffiths.co.uk
-* @version 1.0.6
-* @copyright Adam Griffiths 2009
-*
-* Auth provides a powerful, lightweight and simple interface for user authentication
-*/
-
-
-/**
-* The array which holds your user groups and their ID.
-* If you have a database table for groups, these ID's must be the same as in the database.
-*/
-$config['auth_groups'] = array(
- 'admin' => '1',
- 'editor' => '2',
- 'user' => '100'
- );
-
-/**
-* The default URI string to redirect to after a successful login.
-*/
-$config['auth_login'] = 'admin/dashboard';
-
-/**
-* The default URI string to redirect to after a successful logout.
-*/
-$config['auth_logout'] = 'login';
-
-/**
-* The URI string to redirect to when a user entered incorrect login details or is not authenticated
-*/
-$config['auth_incorrect_login'] = 'login';
-
-
-/**
-* bool TRUE / FALSE
-* Determines whether or not users will be remembered by the auth library
-*/
-$config['auth_remember'] = TRUE;
-
-/**
-* The following options provide the ability to easily rename the directories
-* for your auth views, models, and controllers.
-*
-* Remember to also update your routes file if you change the controller directory
-* MUST HAVE A TRAILING SLASH!
-*/
-$config['auth_controllers_root'] = 'admin/';
-$config['auth_models_root'] = '';
-$config['auth_views_root'] = 'auth/';
-
-/**
-* Set the names for your user tables below (sans prefix, which will be automatically added)
-* ex.: your table is named `ci_users` with 'ci_' defined as your dbprefix in config/database.php, so set it to 'users' below
-*/
-$config['auth_user_table'] = 'users';
-$config['auth_group_table'] = 'groups';
-
-?>
@@ -2,20 +2,20 @@
class Admin extends Application
{
- function Admin()
+ public function __construct()
{
- parent::Application();
+ parent::__construct();
}
- function index()
+ public function index()
{
if(logged_in())
{
- $this->auth->view('dashboard');
+ $this->ag_auth->view('dashboard');
}
else
{
- $this->auth->login();
+ $this->ag_auth->login();
}
}
@@ -3,14 +3,14 @@
class Users extends Application
{
- function Users()
+ public function __construct()
{
- parent::Application();
- $this->auth->restrict('admin'); // restrict this controller to admins only
+ parent::__construct();
+ $this->ag_auth->restrict('admin'); // restrict this controller to admins only
$this->load->model($this->models."usermodel", 'users'); // Load the user model - gets lists of users etc
}
- function manage()
+ public function manage()
{
$data = $this->users->users(); // Grab an array of users from the database
$this->table->set_heading('Username', 'Email', 'Actions'); // Setting headings for the table
@@ -21,23 +21,23 @@ function manage()
$this->table->add_row($key['username'], $key['email'], $actions); // Adding row to table
}
- $this->auth->view('users/manage'); // Load the view
+ $this->ag_auth->view('users/manage'); // Load the view
}
- function delete($id)
+ public function delete($id)
{
$this->users->delete($id);
- $this->auth->view('users/delete_success');
+ $this->ag_auth->view('users/delete_success');
}
- function add()
+ public function add()
{
- $this->auth->register(FALSE);
+ $this->ag_auth->register(FALSE);
}
- function edit($id)
+ public function edit($id)
{
- $this->auth->register(FALSE, TRUE, $id);
+ $this->ag_auth->register(FALSE, TRUE, $id);
}
}
View
@@ -6,32 +6,31 @@
* @category Libraries
* @author Adam Griffiths
* @link http://adamgriffiths.co.uk
-* @version 2.0.0
+* @version 2.0.3
* @copyright Adam Griffiths 2010
*
* Auth provides a powerful, lightweight and simple interface for user authentication .
*/
class Application extends CI_Controller
{
- function __construct()
+ public function __construct()
{
parent::__construct();
log_message('debug', 'Application Loaded');
- $this->load->library('form_validation');
- $this->load->library('auth');
- $this->load->helper(array('url', 'auth'));
+ $this->load->library(array('form_validation', 'ag_auth'));
+ $this->load->helper(array('url', 'ag_auth'));
- $this->config->load('auth');
+ $this->config->load('ag_auth');
}
- function field_exists($value)
+ public function field_exists($value)
{
$field_name = (valid_email($value) ? 'email' : 'username');
- $query = $this->db->get_where('users', array($field_name => $value));
+ $query = $this->db->get_where($this->config->item('auth_user_table'), array($field_name => $value));
if($query->num_rows() <> 0)
{
@@ -45,9 +44,9 @@ function field_exists($value)
} // if($this->field_exists($value) === TRUE)
- } // function field_exists($value)
+ } // public function field_exists($value)
- function register()
+ public function register()
{
$this->form_validation->set_rules('username', 'Username', 'required|min_length[6]|callback_field_exists');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|matches[password_conf]');
@@ -79,10 +78,10 @@ function register()
echo('7');
} // if($this->form_validation->run() == FALSE)
- } // function register()
+ } // public function register()
- function login($redirect = NULL)
+ public function login($redirect = NULL)
{
if($redirect === NULL)
View
@@ -3,7 +3,7 @@
function logged_in()
{
$CI =& get_instance();
- if($CI->auth->logged_in() == TRUE)
+ if($CI->ag_auth->logged_in() == TRUE)
{
return TRUE;
}
@@ -21,7 +21,7 @@ function user_group($group)
{
$CI =& get_instance();
- $system_group = $CI->auth->config['auth_groups'][$group];
+ $system_group = $CI->ag_auth->config['auth_groups'][$group];
if($system_group === $CI->session->userdata('group_id'))
{
@@ -33,14 +33,14 @@ function user_table()
{
$CI =& get_instance();
- return $CI->auth->user_table;
+ return $CI->ag_auth->user_table;
}
function group_table()
{
$CI =& get_instance();
- return $CI->auth->group_table;
+ return $CI->ag_auth->group_table;
}
?>
View
@@ -6,7 +6,7 @@
* @category Libraries
* @author Adam Griffiths
* @link http://adamgriffiths.co.uk
-* @version 2.0.0
+* @version 2.0.3
* @copyright Adam Griffiths 2010
*
* Auth provides a powerful, lightweight and simple interface for user authentication .
@@ -24,10 +24,10 @@ class AG_Auth
* @author Adam Griffiths
* @param array
*
- * The constructor function loads the libraries dependancies and creates the
+ * The constructor public function loads the libraries dependancies and creates the
* login attempts cookie if it does not already exist.
*/
- function __construct($config)
+ public function __construct($config)
{
log_message('debug', 'Auth Library Loaded');
@@ -93,7 +93,7 @@ public function restrict($group = NULL, $single = NULL)
{
redirect($this->config['auth_incorrect_login'], 'refresh');
}
- } // function restrict()
+ } // public function restrict()
/**
@@ -192,40 +192,28 @@ public function logout()
* @access private
* @param string
*/
- private function _generate()
+ private function _generate()
{
- $username = $this->CI->session->userdata('username');
-
- $rand_url = 'http://random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new';
-
- if (ini_get('allow_url_fopen')) {
- // Grab the random string using the easy version if we can
- $token_source = fopen($rand_url, "r");
- $token = fread($token_source, 20);
- } elseif (function_exists('curl_version')) {
- // No easy version, so try cURL
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $rand_url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $token = curl_exec($ch);
- curl_close($ch);
- } else {
- // No love either way, generate a random string ourselves
- $length = 20;
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $token = ”;
- for ($i = 0; $i < $length; $i++) {
- $token .= $characters[mt_rand(0, strlen($characters)-1)];
- }
- }
-
- $identifier = $username . $token;
- $identifier = $this->_salt($identifier);
+ $username = $this->CI->session->userdata('username');
+
+ // No love either way, generate a random string ourselves
+ $length = 20;
+ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $token = "";
+
+ for ($i = 0; $i < $length; $i++)
+ {
+ $token .= $characters[mt_rand(0, strlen($characters)-1)];
+ }
+
+ $identifier = $username . $token;
+ $identifier = $this->_salt($identifier);
- $this->CI->db->query("UPDATE `$this->user_table` SET `identifier` = '$identifier', `token` = '$token' WHERE `username` = '$username'");
+ $this->CI->db->query("UPDATE `$this->user_table` SET `identifier` = '$identifier', `token` = '$token' WHERE `username` = '$username'");
- setcookie("logged_in", $identifier, time()+3600, '/');
- }
+ setcookie("logged_in", $identifier, time()+3600, '/');
+
+ }
/**
@@ -266,7 +254,7 @@ private function _verify_cookie()
* @access private
* @param string
*/
- function view($page, $params = NULL)
+ public function view($page, $params = NULL)
{
if($params !== NULL)
{
Oops, something went wrong.

0 comments on commit 7eb6cc2

Please sign in to comment.