Example #1
0
 /**
  * Saves a user into the database.
  *
  * @param \MicroCMS\Domain\User $user The user to save
  */
 public function save(User $user)
 {
     $userData = array('usr_name' => $user->getUsername(), 'usr_salt' => $user->getSalt(), 'usr_password' => $user->getPassword(), 'usr_role' => $user->getRole(), 'usr_mail' => $user->getMail());
     if ($user->getId()) {
         // The user has already been saved : update it
         $this->getDb()->update('t_user', $userData, array('usr_id' => $user->getId()));
     } else {
         // The user has never been saved : insert it
         $this->getDb()->insert('t_user', $userData);
         // Get the id of the newly created user and set it on the entity.
         $id = $this->getDb()->lastInsertId();
         $user->setId($id);
     }
 }
Example #2
0
    return $app['twig']->render('login.html.twig', array('error' => $app['security.last_error']($request), 'last_username' => $app['session']->get('_security.last_username')));
})->bind('login');
// Register form
$app->get('/register', function (Request $request) use($app) {
    return $app['twig']->render('register.html.twig', array('error' => $app['security.last_error']($request), 'last_username' => $app['session']->get('_security.last_username')));
})->bind('register');
// Register validation
$app->post('/register_check', function (Request $request) use($app) {
    $data = $request->request->all();
    $user = new User();
    $user->setUsername($data["_username"]);
    $salt = substr(md5(time()), 0, 23);
    $user->setSalt($salt);
    $plainPassword = $data["_password"];
    $encoder = $app['security.encoder.digest'];
    $password = $encoder->encodePassword($plainPassword, $user->getSalt());
    $user->setPassword($password);
    $user->setRole("ROLE_USER");
    $user->setMail($data["_mail"]);
    $user->setTelephone($data["_tel"]);
    $user->setVille($data["_ville"]);
    $user->setAdresse($data["_adresse"]);
    $userDao = new UserDAO($app['db']);
    $userDao->save($user);
    return $app->redirect('/login');
})->bind('register_check');
$app->get('/produit', function (Request $request) use($app) {
    $produitDAO = new produitDAO($app['db']);
    $mesProduits = $produitDAO->findAll();
    if (!$app['session']->has('panier')) {
        return $app['twig']->render('produit.html.twig', array('error' => $app['security.last_error']($request), 'last_username' => $app['session']->get('_security.last_username'), 'ProduitsALL' => $mesProduits));