Created
May 21, 2010 17:27
-
-
Save jeremeamia/409121 to your computer and use it in GitHub Desktop.
User Impersonation - Ko3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} | |
} |
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
I think we generally agree to never have one-line non-curly-brace-enclosed bodies of
if
s and loops. This should probably be reflected here.Edit: Because they are an invitation to break code later, of course