diff options
author | Chris Cornutt <enygma@phpdeveloper.org> | 2015-07-19 15:20:54 -0500 |
---|---|---|
committer | Chris Cornutt <enygma@phpdeveloper.org> | 2015-07-19 15:20:54 -0500 |
commit | 27f7203c9c89780da14acf890aeea0cc8dd82f6f (patch) | |
tree | 704ee0f119c5603d92f35dc23a883b388e0f69ea | |
parent | d57dd0bd3cd1cbdd72bbc7d3a4efea3b95663368 (diff) | |
download | gatekeeper-27f7203c9c89780da14acf890aeea0cc8dd82f6f.zip gatekeeper-27f7203c9c89780da14acf890aeea0cc8dd82f6f.tar.gz gatekeeper-27f7203c9c89780da14acf890aeea0cc8dd82f6f.tar.bz2 |
adding docblocks, fixing credentials to pull from .env, authentication now works but "remember me" is still pending
4 files changed, 129 insertions, 25 deletions
diff --git a/src/Psecio/Gatekeeper/Provider/Laravel5/AuthManager.php b/src/Psecio/Gatekeeper/Provider/Laravel5/AuthManager.php index 21fbe11..98522c9 100644 --- a/src/Psecio/Gatekeeper/Provider/Laravel5/AuthManager.php +++ b/src/Psecio/Gatekeeper/Provider/Laravel5/AuthManager.php @@ -6,6 +6,11 @@ use Illuminate\Support\Manager; class AuthManager extends Manager { + /** + * Get the default driver for your manager + * + * @return string Driver type + */ public function getDefaultDriver() { return $this->app['config']['auth.driver']; diff --git a/src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php b/src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php index c17ff09..74293a3 100644 --- a/src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php +++ b/src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php @@ -1,34 +1,37 @@ <?php namespace Psecio\Gatekeeper\Provider\Laravel5; -// namespace App; -use \Illuminate\Support\Facades\Auth; -use \Psecio\Gatekeeper\Gatekeeper; -use \Psecio\Gatekeeper\Provider\Laravel5\UserProvider; -use \Psecio\Gatekeeper\Provider\Laravel5\AuthManager; +use Psecio\Gatekeeper\Gatekeeper; +use Psecio\Gatekeeper\Provider\Laravel5\UserProvider; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\ServiceProvider; use Illuminate\Routing\Router; class AuthServiceProvider extends ServiceProvider { + /** + * Register (start) the service provider + * Sets up the Gatekeeper instance with init() call + */ public function register() { - error_log(get_class().' :: '.__FUNCTION__); - $config = array( - 'username' => 'gk42', - 'password' => 'gk42', - 'host' => '127.0.0.1', - 'name' => 'gatekeeper' + 'username' => env('GATEKEEPER_USER'), + 'password' => env('GATEKEEPER_PASS'), + 'host' => env('GATEKEEPER_HOST'), + 'name' => env('GATEKEEPER_DATABASE'), ); Gatekeeper::init(null, $config); } + /** + * Boot the provider, adding the "gatekeeper" type to the Auth handling + * + * @param Router $router Laravel router instance + */ public function boot(Router $router) { - error_log(get_class().' :: '.__FUNCTION__); - Auth::extend('gatekeeper', function($app) { return new UserProvider(); }); diff --git a/src/Psecio/Gatekeeper/Provider/Laravel5/UserAuthenticatable.php b/src/Psecio/Gatekeeper/Provider/Laravel5/UserAuthenticatable.php index 35c7056..7be9d06 100644 --- a/src/Psecio/Gatekeeper/Provider/Laravel5/UserAuthenticatable.php +++ b/src/Psecio/Gatekeeper/Provider/Laravel5/UserAuthenticatable.php @@ -1,36 +1,109 @@ <?php namespace Psecio\Gatekeeper\Provider\Laravel5; + use Psecio\Gatekeeper\UserModel; use Illuminate\Contracts\Auth\Authenticatable; class UserAuthenticatable implements Authenticatable { + /** + * Current User model instance + * @var \Psecio\Gatekeeper\UserModel + */ private $model; + /** + * The current Gatekeeper "remember me" token name + * @var string + */ + private $tokenName = 'gktoken'; + + /** + * Init the object and set the current User model instance + * + * @param \Psecio\Gatekeeper\UserModel $model User instance + */ public function __construct(UserModel $model) { $this->model = $model; } + /** + * Allow the fetching of properties directly from the model + * + * @param string $name Name of the property to fetch + * @return mixed Property value + */ + public function __get($name) + { + return $this->model->$name; + } + + /** + * Allow for the direct calling of methods on the object + * + * @param string $name Function name + * @param array $args Function arguments + * @return mixed Function call return value + */ + public function __call($name, array $args) + { + return call_user_func_array([$this->model, $name], $args); + } + + /** + * Get the primary identifier for the curent user + * + * @return string Username + */ public function getAuthIdentifier() { return $this->model->username; } + + /** + * Get the current user's password (hashed value) + * + * @return string Hashed password string + */ public function getAuthPassword() { return $this->model->password; } + + /** + * Get the current token value for the "remember me" handling + * + * @return string Token value (hash) + */ public function getRememberToken() { - return null; +error_log(get_class().' :: '.__FUNCTION__); + $token = $this->model->authTokens[0]->token; } + + /** + * Set the "remember me" token value + * + * @param string $value Token value + */ public function setRememberToken($value) { - return null; +error_log(get_class().' :: '.__FUNCTION__); + $token = $this->model->authTokens[0]; + $token->token($value); + $token->save(); } + + /** + * Get the name for the current "remember me" token + * + * @return string Token name + */ public function getRememberTokenName() { - return null; +error_log(get_class().' :: '.__FUNCTION__); + return $this->tokenName; } }
\ No newline at end of file diff --git a/src/Psecio/Gatekeeper/Provider/Laravel5/UserProvider.php b/src/Psecio/Gatekeeper/Provider/Laravel5/UserProvider.php index 0ffb19e..de6da3f 100644 --- a/src/Psecio/Gatekeeper/Provider/Laravel5/UserProvider.php +++ b/src/Psecio/Gatekeeper/Provider/Laravel5/UserProvider.php @@ -10,25 +10,46 @@ use Psecio\Gatekeeper\Gatekeeper; class UserProvider implements UserProviderInterface { + /** + * Get the user iformation, fetched by provided identifier + * + * @param string $identifier Unique user identifier + * @return \Illuminate\Contracts\Auth\Authenticatable|null + */ public function retrieveById($identifier) { - error_log(get_class().' :: '.__FUNCTION__); - - $user = Gatekeeper::findUserById($identifier); - if ($user === null) { + $user = (is_int($identifier)) + ? Gatekeeper::findUserById($identifier) + : Gatekeeper::findUserByUsername($identifier); + if ($user === false) { return null; } return new UserAuthenticatable($user); } + /** + * Fetch the user by the value of the "remember" me token + * + * @param string $identifier User identifier + * @param string $token Token value + * @return \Illuminate\Contracts\Auth\Authenticatable|null + */ public function retrieveByToken($identifier, $token) { error_log(get_class().' :: '.__FUNCTION__); + error_log(print_r($identifier, true).' - '.$token); } + /** + * Update the user's "remember me" token value + * + * @param Authenticatable $user User instance + * @param string $token Token value + * @return ? + */ public function updateRememberToken(Authenticatable $user, $token) { - error_log(get_class().' :: '.__FUNCTION__); + error_log(get_class().' :: '.__FUNCTION__.' token: '.$token); } /** @@ -41,10 +62,10 @@ class UserProvider implements UserProviderInterface { if (isset($credentials['email'])) { $user = Gatekeeper::findUserByEmail($credentials['email']); - } elseif (isset($credentials['username'])) - $user = Gatekeeper::findUserByUsername($credentials['email']); + } elseif (isset($credentials['username'])) { + $user = Gatekeeper::findUserByUsername($credentials['username']); } - if ($user === null) { + if ($user === false) { return null; } $userAuth = new UserAuthenticatable($user); @@ -54,12 +75,14 @@ class UserProvider implements UserProviderInterface /** * Validate a user against the given credentials. * - * @param \Illuminate\Contracts\Auth\Authenticatable $user + * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param array $credentials * @return bool */ public function validateCredentials(Authenticatable $user, array $credentials) { +error_log(print_r($credentials, true)); + $username = $user->getAuthIdentifier(); $credentials = [ 'username' => $username, |