public static function finInscription($request, $context) { try { // On cherche l'utilisateur par son identifiant if (is_null(utilisateurTable::getUserByLogin($request["identifiantInscrip"]))) { // Si l'identifiant n'existe pas, on continue $data = array("identifiant" => $request["identifiantInscrip"], "pass" => sha1($request["passInscrip"]), "nom" => $request["nomInscrip"], "prenom" => $request["prenomInscrip"], "statut" => "", "avatar" => ""); $u = new utilisateur($data); $u->id = $u->save(); if (is_null($u->id)) { throw new Exception("Il y a eu une erreur pour inscrire l'utilisateur. Désolé."); } else { context::setSessionAttribute("succes", "Le compte a été créé"); context::redirect('twitty.php'); } } else { throw new Exception("Il existe déjà un utilisateur avec le même identifiant."); } } catch (Exception $e) { context::setSessionAttribute("erreur", $e); return context::ERROR; } }
public static function vote($request, $context) { //print_r($request); if (!empty($request['idtweet']) && $context->getSessionAttribute('is_logged') == 1) { $voteInfo['message'] = $request['idtweet']; $voteInfo['utilisateur'] = $_SESSION['id']; $vote = new vote($voteInfo); $vote->save(); $tweetInfo['id'] = $request['idtweet']; $nbVotes = vote::getVote($request['idtweet']); //print_r($nbVotes); $tweetInfo['nbVotes'] = $nbVotes[0]['count']; $tweet = new tweet($tweetInfo); $tweet->save(); context::redirect(history . back()); return context::SUCCESS; } return context::ERROR; }