예제 #1
0
 public function test_create_method_creates_new_user_with_username_and_password()
 {
     $user = new User();
     $user->setUsername('brian');
     $user->setPassword('password');
     $created = User::create('brian', 'password');
     $this->assertEquals($user, $created);
 }
예제 #2
0
    $app->render('login.phtml');
});
$app->post('/login', function () use($app, $authService, $userRepo) {
    $input = new Input\Login($app->request()->post('login'));
    if ($input->isValid()) {
        if ($authService->canLogin($input->username, $input->password)) {
            $authService->login($userRepo->getByUsername($input->username), AUTHCOOKIE, function () use($app) {
                $app->response()->redirect('/admin/post', 303);
            });
        } else {
            $input->setMessageFor("username", "Invalid username or password");
        }
    }
    $app->render('login.phtml', ['login' => $input]);
});
$app->get('/logout', function () use($app) {
    $app->setCookie(AUTHCOOKIE, 'DELETED', time());
    $app->response()->redirect('/login', 303);
});
$app->get('/register', function () use($app) {
    $app->render('register.phtml');
});
$app->post('/register', function () use($app, $authService, $userRepo) {
    $input = Input\User::create($app->request()->post('user'), $userRepo);
    if ($input->isValid()) {
        $authService->register(Entities\User::create($input->username, $input->password), AUTHCOOKIE, function () use($app) {
            $app->response()->redirect('/admin/post', 303);
        });
    }
    $app->render('register.phtml', ['user' => $input]);
});