diff --git a/src/Auth.php b/src/Auth.php index c2a662c..96553e8 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -2,6 +2,8 @@ namespace EesyPHP; +use EesyPHP\Auth\User; + class Auth { @@ -264,14 +266,23 @@ class Auth { /** * Helper to set current authenticated user * @param \EesyPHP\Auth\User $user The current authenticated user object - * @param string $method Method used to authenticate the user + * @param string|null $method Method used to authenticate the user. If not null, user information + * will be changed in session. * @return void */ - public static function set_user($user, $method) { + public static function set_user($user, $method=null) { + if (!$user instanceof User) + throw new \Exception( + "Provided user is not an instance of \\EesyPHP\\Auth\\User: ".vardump($user) + ); + self :: $user = $user; + + if (!$method) return; + + // Method provided: update user info in session and trigger hook Log :: debug( 'User %s authenticated using method %s and backend %s', - $user->username, $method, $user->backend); - self :: $user = $user; + $user, $method, $user->backend); self :: $logged_method = $method; $_SESSION['user'] = serialize($user); $_SESSION['auth_method'] = $method;