public function testIssue1_AuthenticateFailsWithErrors() { $wt = new WatchTower(); $wt->watch(new Sentry\Authentication\Callback('auth', function (Event $e) { $e->triggerError(Sentry\Sentry::INVALID, 'Not valid'); $e->stopPropagation(); })); $identity = $wt->authenticate('superman', 'lois lane'); self::assertTrue($identity->hasErrors()); self::assertFalse($identity->isAuthenticated()); }
* * @license MIT License * @author David Lundgren * @link http://dlundgren.github.io/watchtower * @copyright 2015. David Lundgren */ /** * This is a basic example of how to use WatchTower */ require_once __DIR__ . '/../vendor/autoload.php'; use WatchTower\WatchTower; use WatchTower\Event\Event; $wt = new WatchTower(); $users = new \WatchTower\Sentry\Identification\InMemory('id'); $users->add('superman', (object) ['name' => 'Khalel', 'alias' => 'clark kent']); $wt->watch($users); $wt->watch(new \WatchTower\Sentry\Authentication\Callback('auth', function (Event $event) { $identity = $event->identity(); if ($identity->isIdentified()) { $cred = $identity->credential(); if (!empty($cred) && $cred === 'password') { return; } $event->triggerError(\WatchTower\Sentry\Sentry::INVALID, "Invalid username or password"); } })); // fails authentication and identification $identity = $wt->authenticate("bizarro", 'forever man'); if ($identity->isIdentified() === false) { echo 'Failure: ' . join(', ', $identity->getErrors()) . "<br>\n"; }