public function index() { //If the register form was sent if (Form::exists('login_form')) { //Check if User exists $user = Client::getOneBy(array('_mail' => Form::get('mail'))); //Confirm if PW matches if ($user && $user->getPassword() == Client::encryptPassword(Form::get('password'))) { Session::connect($user); return \App\Component\Redirect::to('/'); } $error = "Vos informations de connexion sont incorrects. Merci de réessayer."; return View::render("login/index.php", array('error' => $error)); } return View::render("index/index.php"); }
public function index() { //If the register form was sent if (Form::exists('register_form')) { //We check if all the input are filled if (Form::checkEmpty(array('mainAddress', 'firstName', 'mail', 'name', 'password', 'password_check', 'phoneNumber', 'birthday'))) { $error = "Veuillez remplir tous les champs"; return View::render("register/index.php", array('error' => $error)); } //We check if the mail address is not already taken if (Client::getOneBy(array('_mail' => Form::get('mail')))) { $error = "Cette adresse e-mail est déjà associée à un compte. Veuillez en choisir une autre."; return View::render("register/index.php", array('error' => $error)); } //We check if the password and the check are the same if (Form::get('password') != Form::get('password_check')) { $error = "Les mots de passe ne correspondent pas."; return View::render("register/index.php", array('error' => $error)); } //We create a new User, and associate the values $user = new Client(); $user->setFirstName(Form::get('firstName')); $user->setMail(Form::get('mail')); $user->setName(Form::get('name')); $user->setPassword(Form::get('password')); $user->setPhoneNumber(Form::get('phoneNumber')); $user->setBirthday(Form::get('birthday')); //We save this User in the DB $user->save(); $address = new \App\Model\Address(); $address->setAddress(Form::get('mainAddress')); $address->setUser($user); $address->save(); $user->setAddress($address); $user->save(); return View::render("register/complete.php", array('user' => $user)); } return View::render("register/index.php"); }
public function index() { //If the register form was sent if (Form::exists('profile_form')) { //We check if all the input are filled if (Form::checkEmpty(array('mainAddress', 'firstName', 'mail', 'name', 'password', 'password_check', 'phoneNumber', 'birthday'))) { $error = "Veuillez remplir tous les champs"; return View::render("register/index.php", array('error' => $error)); } $user = Session::getUser(); //We check if the password and the check are the same if (Form::exists('password') && Form::get('password') != "") { if (Form::get('password') != Form::get('password_check')) { $error = "Les mots de passe ne correspondent pas."; return View::render("register/index.php", array('error' => $error)); } else { $user->setPassword(Form::get('password')); } } //associate the values $user->setFirstName(Form::get('firstName')); $user->setName(Form::get('name')); $user->setPhoneNumber(Form::get('phoneNumber')); $user->setBirthday(Form::get('birthday')); //We save this User in the DB $user->save(); $adress = new \App\Model\Address(); $adress->setAddress(Form::get('mainAddress')); $adress->setUser($user); $adress->save(); $user->setAddress($adress); $user->save(); Session::connect($user); return View::render("profile/complete.php", array('user' => $user)); } $user = Session::getUser(); return View::render("profile/index.php", array('user' => $user)); }
public function gererCommande($id = 0) { $restaurateur = Restaurateur::getOneBy(array('_id' => new \MongoId(Session::getUser()->getId()))); //If we are not connected as a Restaurateur, send to the login page if (!Session::isConnected() || Session::getUser()->getType() != USER_RESTAURATEUR) { return Redirect::to('/restaurateur/login'); } //If no restaurant is specified, display the list if ($id == 0) { $commandes = Commande::getByRestaurateur($restaurateur); return View::render("restaurateur/gestionCommande.php", array('commandes' => $commandes)); } $commande = Commande::getOneBy(array('_id' => new \MongoId($id))); if ($commande->getStatus() < Commande::COMMAND_STATUS_PREPARING) { $commande->setStatus(Commande::COMMAND_STATUS_PREPARING); $commande->save(); } if (Form::exists('finir_commande_form')) { $commande->setStatus(commande::COMMAND_STATUS_READY); $commande->save(); $commandes = Commande::getByRestaurateur($restaurateur); return View::render("restaurateur/gestionCommande.php", array('commandes' => $commandes)); } return View::render("restaurateur/prepareCommande.php", array('commande' => $commande)); }
public function validateCommand($commandId) { //If User is not logged in if (!Session::isConnected() || Session::getUser()->getType() != USER_CLIENT) { Session::addFlashMessage("Non connecté", "error", "Veuillez vous connecter avant de continuer."); Redirect::to('/restaurant'); } //If it doesn't exist, return to the list $command = Commande::getOneBy(array('_id' => new \MongoId($commandId))); if (!$command) { Redirect::to('/restaurant'); } //If we just validated the command if (Form::exists('validate_command_form')) { $datetime = Form::get('datetime'); if ($datetime == "" || is_null($datetime)) { Session::addFlashMessage("Erreur :", 'error', "Vous devez indiquer une date et une heure."); $error = "Veuillez indiquer un nom de menu"; return View::render("restaurant/validateCommand.php", array('error' => $error, 'command' => $command)); } $command->setDateTime(Form::get('datetime')); $command->setStatus(Commande::COMMAND_STATUS_VALIDATED); $client = $command->getClient(); $address = $command->getAddress(); $client->setAddress($address); $client->save(); return View::render("restaurant/payCommand.php", array('command' => $command)); } $command->save(); return View::render("restaurant/validateCommand.php", array('command' => $command)); }
public function editeRestaurant($id = 0) { //If we are not connected as an entrepreneur, send to the login page if (!Session::isConnected() || Session::getUser()->getType() != USER_ENTREPRENEUR) { Redirect::to('/entrepreneur/login'); } //If id is not set, we display the list of restaurants if ($id == 0) { $restaurants = Restaurant::getBy(array()); return View::render("entrepreneur/listeEditeRestaurant.php", array('restaurants' => $restaurants)); } $restaurant = Restaurant::getOneBy(array('_id' => new \MongoId($id))); if (!$restaurant) { return Redirect::to('/entrepreneur/editeRestaurant'); } //We select all the Restaurateurs $restaurateurs = Restaurateur::getBy(array()); if (Form::exists('restaurant_edit_form')) { //We check if all the input are filled if (Form::checkEmpty(array('name')) || Form::checkEmpty(array('description'))) { Session::addFlashMessage("Erreur :", 'error', "Tous les champs ne sont pas remplis."); $error = "Veuillez remplir tous les champs"; return View::render("entrepreneur/editeRestaurant.php", array('error' => $error, 'restaurateurs' => $restaurateurs, 'restaurant' => $restaurant)); } //We check if the name is not already taken $found = Restaurant::getOneBy(array('name' => Form::get('name'))); if ($found && $found->getId() != $restaurant->getId()) { Session::addFlashMessage("Erreur :", 'error', "Ce nom de restaurant est non disponible."); $error = "Ce nom de restaurant existe déjà. Veuillez en choisir une autre."; return View::render("entrepreneur/editeRestaurant.php", array('error' => $error, 'restaurateurs' => $restaurateurs, 'restaurant' => $restaurant)); } //We create a new Restaurant, and associate the values $restaurant->setName(Form::get('name')); $restaurant->setDescription(Form::get('description')); //TODO: Set the picture from the form //We save this Restaurant in the DB $restaurant->save(); //We remove the current Restaurateur $restaurateur = $restaurant->getRestaurateur(); if ($restaurateur) { $restaurateur->removeRestaurant($restaurant); $restaurateur->save(); $restaurant->removeRestaurateur(); $restaurant->save(); } //We add the Restaurateur to the Restaurant $restaurateurId = Form::get('restaurateur'); if ($restaurateurId != "") { $restaurateur = Restaurateur::getOneBy(array('_id' => new \MongoId($restaurateurId))); //If the Restaurateur exist, we add the Restaurant to it if ($restaurateur) { $restaurateur->addRestaurant($restaurant); $restaurateur->save(); $restaurateurAdded = true; } } Session::addFlashMessage("Restaurant édité avec succès", 'success', "Le restaurant " . $restaurant->getName() . " a été édité avec succès."); Redirect::to('/entrepreneur'); } return View::render("entrepreneur/editeRestaurant.php", array('restaurateurs' => $restaurateurs, 'restaurant' => $restaurant)); }