Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/kohana/auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody Gilk committed Apr 11, 2010
2 parents f81b2cb + 47b5999 commit 4720c0d
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 139 deletions.
4 changes: 2 additions & 2 deletions classes/kohana/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function get_user()
*
* @param string username to log in
* @param string password to check against
* @param boolean enable auto-login
* @param boolean enable autologin
* @return boolean
*/
public function login($username, $password, $remember = FALSE)
Expand All @@ -119,7 +119,7 @@ public function login($username, $password, $remember = FALSE)
* Log out a user by removing the related session variables.
*
* @param boolean completely destroy the session
* @param boolean remove all tokens for user
* @param boolean remove all tokens for user
* @return boolean
*/
public function logout($destroy = FALSE, $logout_all = FALSE)
Expand Down
10 changes: 4 additions & 6 deletions classes/kohana/auth/file.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* File Auth driver.
* Note: this Auth driver does not support roles nor auto-login.
*
* $Id: File.php 3769 2008-12-15 00:48:56Z zombor $
* Note: this Auth driver does not support roles nor autologin.
*
* @package Auth
* @author Kohana Team
Expand Down Expand Up @@ -31,10 +29,10 @@ public function __construct($config)
*
* @param string username
* @param string password
* @param boolean enable auto-login (not supported)
* @param boolean enable autologin (not supported)
* @return boolean
*/
public function _login($username, $password, $remember)
protected function _login($username, $password, $remember)
{
if (isset($this->users[$username]) AND $this->users[$username] === $password)
{
Expand Down Expand Up @@ -69,4 +67,4 @@ public function password($username)
return isset($this->users[$username]) ? $this->users[$username] : FALSE;
}

} // End Auth_File_Driver
} // End Auth File
60 changes: 30 additions & 30 deletions classes/kohana/auth/orm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/**
* ORM Auth driver.
*
* $Id: ORM.php 4335 2009-05-06 23:46:02Z kiall $
*
* @package Auth
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
Expand All @@ -14,8 +12,7 @@ class Kohana_Auth_ORM extends Auth {
/**
* Checks if a session is active.
*
* @param string role name
* @param array collection of role names
* @param mixed role name string, role ORM object, or array with role names
* @return boolean
*/
public function logged_in($role = NULL)
Expand All @@ -32,29 +29,29 @@ public function logged_in($role = NULL)

if ( ! empty($role))
{

// If role is an array
// Multiple roles to check
if (is_array($role))
{
// Check each role
foreach ($role as $role_iteration)
foreach ($role as $_role)
{
if ( ! is_object($role_iteration))
if ( ! is_object($_role))
{
$role_iteration = ORM::factory('role', array('name' => $role_iteration));
$_role = ORM::factory('role', array('name' => $_role));
}

// If the user doesn't have the role
if( ! $user->has('roles', $role_iteration))
if ( ! $user->has('roles', $_role))
{
// Set the status false and get outta here
$status = FALSE;
break;
}
}
}
// Single role to check
else
{
// Else just check the one supplied roles
if ( ! is_object($role))
{
// Load the role
Expand All @@ -75,18 +72,18 @@ public function logged_in($role = NULL)
*
* @param string username
* @param string password
* @param boolean enable auto-login
* @param boolean enable autologin
* @return boolean
*/
public function _login($user, $password, $remember)
protected function _login($user, $password, $remember)
{
if ( ! is_object($user))
{
$username = $user;

// Load the user
$user = ORM::factory('user');
$user->where($user->unique_key($username), "=", $username)->find();
$user->where($user->unique_key($username), '=', $username)->find();
}

// If the passwords match, perform a login
Expand All @@ -103,7 +100,7 @@ public function _login($user, $password, $remember)
$token->save();

// Set the autologin cookie
cookie::set('authautologin', $token->token, $this->config['lifetime']);
Cookie::set('authautologin', $token->token, $this->config['lifetime']);
}

// Finish the login
Expand All @@ -119,7 +116,7 @@ public function _login($user, $password, $remember)
/**
* Forces a user to be logged in, without specifying a password.
*
* @param mixed username
* @param mixed username string, or user ORM object
* @return boolean
*/
public function force_login($user)
Expand All @@ -130,10 +127,10 @@ public function force_login($user)

// Load the user
$user = ORM::factory('user');
$user->where($user->unique_key($username), "=", $username)->find();
$user->where($user->unique_key($username), '=', $username)->find();
}

// Mark the session as forced, to prevent users from changing account information
// Mark the session as forced, to prevent users from changing account information
$this->session->set('auth_forced', TRUE);

// Run the standard completion
Expand All @@ -147,7 +144,7 @@ public function force_login($user)
*/
public function auto_login()
{
if ($token = cookie::get('authautologin'))
if ($token = Cookie::get('authautologin'))
{
// Load the token and user
$token = ORM::factory('user_token', array('token' => $token));
Expand All @@ -160,7 +157,7 @@ public function auto_login()
$token->save();

// Set the new token
cookie::set('authautologin', $token->token, $token->expires - time());
Cookie::set('authautologin', $token->token, $token->expires - time());

// Complete the login with the found data
$this->complete_login($token->user);
Expand All @@ -178,22 +175,25 @@ public function auto_login()
}

/**
* Log a user out and remove any auto-login cookies.
* Log a user out and remove any autologin cookies.
*
* @param boolean completely destroy the session
* @param boolean remove all tokens for user
* @return boolean
*/
public function logout($destroy = FALSE, $logout_all = FALSE)
{
if ($token = cookie::get('authautologin'))
// Set by force_login()
$this->session->delete('auth_forced');

if ($token = Cookie::get('authautologin'))
{
// Delete the autologin cookie to prevent re-login
cookie::delete('authautologin');
Cookie::delete('authautologin');

// Clear the autologin token from the database
$token = ORM::factory('user_token', array('token' => $token));

if ($token->loaded() AND $logout_all)
{
ORM::factory('user_token')->where('user_id', '=', $token->user_id)->delete_all();
Expand All @@ -210,7 +210,7 @@ public function logout($destroy = FALSE, $logout_all = FALSE)
/**
* Get the stored password for a username.
*
* @param mixed username
* @param mixed username string, or user ORM object
* @return string
*/
public function password($user)
Expand All @@ -221,17 +221,17 @@ public function password($user)

// Load the user
$user = ORM::factory('user');
$user->where($user->unique_key($username), "=", $username)->find();
$user->where($user->unique_key($username), '=', $username)->find();
}

return $user->password;
}

/**
* Complete the login for a user by incrementing the logins and setting
* session data: user_id, username, roles
* session data: user_id, username, roles.
*
* @param object user model object
* @param object user ORM object
* @return void
*/
protected function complete_login($user)
Expand All @@ -248,4 +248,4 @@ protected function complete_login($user)
return parent::complete_login($user);
}

} // End Auth_ORM_Driver
} // End Auth ORM
19 changes: 9 additions & 10 deletions classes/model/auth/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

class Model_Auth_Role extends ORM {

// Relationships
protected $_has_many = array('users' => array('through' => 'roles_users'));

protected $_rules = array
(
'name' => array
(
'not_empty' => NULL,
'min_length' => array(4),
'max_length' => array(32),
// Validation rules
protected $_rules = array(
'name' => array(
'not_empty' => NULL,
'min_length' => array(4),
'max_length' => array(32),
),
'description' => array
(
'max_length' => array(255),
'description' => array(
'max_length' => array(255),
),
);

Expand Down
Loading

0 comments on commit 4720c0d

Please sign in to comment.