/** * Insertion Utilisateur * * @param Application $app Silex Application * @param Request $request Requete Entrante */ public function utilisateurInsertAction(Application $app, Request $request) { $salt = substr(md5(time()), 0, 23); $utilisateur = new \SIOC\donnees\Utilisateur(); $promotion = new \SIOC\donnees\Promotion(); $cursus = new \SIOC\donnees\Cursus(); if (null !== $request->request->get('id')) { $utilisateur->setId($request->request->get('id')); } $utilisateur->setUsername($request->request->get('username')); $utilisateur->setNom($request->request->get('nom')); $utilisateur->setPrenom($request->request->get('prenom')); $utilisateur->setMail($request->request->get('email')); $utilisateur->setSalt($salt); $encoder = $app['security.encoder.digest']; $utilisateur->setPassword($encoder->encodePassword($request->request->get('password'), $utilisateur->getSalt())); $utilisateur->setRole($request->request->get('role')); if ($utilisateur->getRole() == 'ROLE_ELEVE') { $promotion->setId($request->request->get('promo')); $cursus->setId($request->request->get('cursus')); } $app['dao.utilisateur']->save($utilisateur, $promotion, $cursus); $role = $app['security.token_storage']->getToken()->getUser()->getRole(); if ($role == "ROLE_ADMIN") { return $app->redirect('/utilisateur'); } else { return $app->redirect('/eleve'); } }
/** * Insertion Promotion * * @param Application $app Silex Application * @param Request $request Requete Entrante */ public function promotionInsertAction(Application $app, Request $request) { $promotion = new \SIOC\donnees\Promotion(); if (null !== $request->request->get('id')) { $promotion->setId($request->request->get('id')); } $promotion->setLibelle($request->request->get('libelle')); $promotion->setAnnee($request->request->get('annee')); $app['dao.promotion']->save($promotion); return $app->redirect('/promotion'); }