Example #1
0
 public function test_create_sets_data_repository_and_messages()
 {
     $data = $this->getObjectValue($this->input, 'data');
     $inputMsgs = $this->getObjectValue($this->input, 'messages');
     $input = User::create($data, $this->repo);
     //fixture not treated as same type for assertEquals - hence the three asserts
     $iData = $this->getObjectValue($input, 'data');
     $repo = $this->getObjectValue($input, 'repository');
     $msgs = $this->getObjectValue($input, 'messages');
     $this->assertEquals($data, $iData);
     $this->assertEquals($this->repo, $repo);
     $this->assertEquals($inputMsgs, $msgs);
 }
Example #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]);
});