Skip to content

Instantly share code, notes, and snippets.

@jeremeamia
Created May 21, 2010 17:27
Show Gist options
  • Save jeremeamia/409121 to your computer and use it in GitHub Desktop.
Save jeremeamia/409121 to your computer and use it in GitHub Desktop.
User Impersonation - Ko3
<?php defined('SYSPATH') or die('No direct script access.');
// Extending Auth to support user impersonation functions
class Auth extends Kohana_Auth {
public function impersonate(ORM $user)
{
if ( ! $user->loaded())
throw new Exception;
$this->session->set('impersonator', $this->get_user());
$this->logout();
$this->force_login($user);
}
public function abdicate()
{
if ( ! $this->is_impersonating())
return FALSE;
$impersonator = $this->get_impersonator();
$this->session->delete('impersonator');
if ( ! $impersonator->loaded())
throw new Exception;
$this->logout();
$this->force_login($impersonator);
}
public function is_impersonating()
{
return (bool) $this->session->get('impersonator');
}
public function get_impersonator()
{
return $this->session->get('impersonator');
}
}
@alanhogan
Copy link

I think we generally agree to never have one-line non-curly-brace-enclosed bodies of ifs and loops. This should probably be reflected here.
Edit: Because they are an invitation to break code later, of course

@jeremeamia
Copy link
Author

This actually reflects the regular Kohana coding guidelines, which I was following when I wrote this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment