Beispiel #1
0
 public function userSave($password, $cookie, $em)
 {
     $this->user->setCreatedNow();
     $salt = HashGenerator::generateSalt();
     $this->user->setSalt($salt);
     $this->user->setToken($cookie);
     $hash = HashGenerator::generateHash($password, $salt);
     $this->user->setHash($hash);
     $em->persist($this->user);
     $em->flush();
     return $this->user;
 }
Beispiel #2
0
            }
        }
    }
    $app->render('login_form.html', array('data' => $_POST, 'page' => $page));
})->via('GET', 'POST')->name('login');
$app->get('/logout', function () use($app) {
    $app->loginHelper->logout();
    $app->redirect('/');
});
$app->map('/register', function () use($app) {
    if ($app->request->isGet()) {
        $app->render('register.html');
    } else {
        $cookie = $app->getCookie('token');
        if (!$cookie) {
            $cookie = HashGenerator::generateSalt();
            $app->setCookie('token', $cookie, '1 month');
        }
        $validation = new \Uppu3\Helper\DataValidator();
        $userHelper = new \Uppu3\Helper\UserHelper($_POST, $app->em, $cookie);
        $user = $userHelper->user;
        $validation->validateUser($user, $_POST);
        if (empty($validation->error)) {
            $userHelper->userSave($app->request->params('password'), $cookie, $app->em);
            $id = $userHelper->user->getId();
            $app->loginHelper->authenticateUser($userHelper->user);
            $app->redirect("users/{$id}");
        } else {
            $app->render('register.html', array('errors' => $validation->error, 'data' => $_POST));
        }
    }