summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Cornutt <enygma@phpdeveloper.org>2015-07-21 16:19:59 -0500
committerChris Cornutt <enygma@phpdeveloper.org>2015-07-21 16:19:59 -0500
commit424be3085fe2779f0072ad323149b6826ea20273 (patch)
tree20ff5d6c8b6b12e1b590e8d30eb905cf65f36cbc
parent6abdc560501debc0fd8ec74e2399b4001b82919c (diff)
downloadgatekeeper-424be3085fe2779f0072ad323149b6826ea20273.zip
gatekeeper-424be3085fe2779f0072ad323149b6826ea20273.tar.gz
gatekeeper-424be3085fe2779f0072ad323149b6826ea20273.tar.bz2
adding a custom validator (gk_unique) to the provider for use with the Gatekeeper find* handling
-rw-r--r--src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php b/src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php
index 74293a3..df664d4 100644
--- a/src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php
+++ b/src/Psecio/Gatekeeper/Provider/Laravel5/AuthServiceProvider.php
@@ -32,10 +32,28 @@ class AuthServiceProvider extends ServiceProvider
*/
public function boot(Router $router)
{
+ // Add Gatekeeper to the Auth provider list
Auth::extend('gatekeeper', function($app) {
return new UserProvider();
});
+ // Create a new "unique" (gkunique) validator for unique user checking
+ Validator::extend('gk_unique', function($attribute, $value, $parameters) {
+ $type = (isset($parameters[0])) ? $parameters[0] : 'user';
+
+ // strip a training "s" if there is one
+ if (substr($type, -1) === 's') {
+ $type = substr($type, 0, strlen($type)-1);
+ }
+ $method = 'find'.ucwords($type).'By'.ucwords($attribute);
+ try {
+ $user = Gatekeeper::$method($value);
+ return ($user === false);
+ } catch (\Exception $e) {
+ return false;
+ }
+ });
+
parent::boot($router);
}
} \ No newline at end of file