public function initNewUser(User $user)
 {
     if (!$user->isNew()) {
         throw new \RuntimeException('Cannot initialize existing user');
     }
     $this->hashPassword($user);
     $user->refresh();
 }
 public function __construct()
 {
     parent::__construct();
     $this->username = '******';
     $this->password = '******';
     $this->identifier = 'id.test';
     $this->token = 'token.test';
     $this->timeout = 10;
 }
 public function __construct()
 {
     parent::__construct();
     $this->id = 1;
     $this->username = '******';
     $this->password = '******';
     $this->identifier = 'some_id';
     $this->token = 'some_token';
     $this->timeout = 10;
     $this->date = \DateTime::createFromFormat('m/d/Y', '06/20/1986');
 }
 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);
 }
Exemple #5
0
 public function setUser(User $user)
 {
     $this->user = $user;
     $user->addPost($this);
 }
 public function setAuthCookie($cookiename, User $user)
 {
     $this->slim->setcookie($cookiename, $user->getTokenString());
 }
Exemple #7
0
 public static function create($username, $password)
 {
     $user = new User();
     $user->setUsername($username);
     $user->setPassword($password);
     return $user;
 }
 public function isNew()
 {
     $this->__load();
     return parent::isNew();
 }
Exemple #9
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]);
});