Пример #1
0
 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());
 }
Пример #2
0
/**
 * WatchTower Authentication system
 *
 * @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');