Example #1
0
 public static function create($data, $repo, $msgs = [])
 {
     $user = new User($data, $msgs);
     $user->setRepository($repo);
     return $user;
 }
 public function __construct()
 {
     $user = new UserNoPosts();
     $data = ['username' => $user->getUsername(), 'password' => $user->getPassword(), 'passwordConfirm' => $user->getPassword()];
     parent::__construct($data);
 }
Example #3
0
 protected function getInput($vals, $msgs = [])
 {
     $inputData = $this->getObjectValue($this->input, 'data');
     $data = array_merge($inputData, $vals);
     $input = new User($data, $msgs);
     return $input->setRepository($this->repo);
 }
Example #4
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]);
});