* Traitement du formulaire de création d'utilisateur. */ if (isset($_POST["registration"])) { $errors = array(); $formValid = true; $acceptcg = Tools::prepareUserArgBoolean($_POST["acceptpp"]); $email = Tools::prepareUserArgString($_POST["email"]); $pwd = Tools::prepareUserArgString($_POST["pwd"]); $pwd2 = Tools::prepareUserArgString($_POST["pwd2"]); // Si no validé. if ($acceptcg == false) { $formValid = false; $errors["acceptpp"] = "You must accept our privacy police."; } // Si ce n'est pas en format email. if (!Tools::verifyEmail($email)) { $formValid = false; $errors["email"] = "You must insert a valid email."; } // Si mot de passe valide if (!Tools::verifyPassword($pwd)) { $formValid = false; $errors["pwd"] = "You must insert a valid password see password <a href=\"#\">hint</a>."; } else { if ($pwd !== $pwd2) { $formValid = false; $errors["pwd2"] = "You must insert the same password."; } } // Tente de créer le nouvel utilisateur uniquement si les autres tests sont valides. if ($formValid) {
try { $message = Message::findById($id); if ($message == null) { throw new Exception("Invalid ID message"); } $message->setUnread(true, Session::getSessionEmail())->doUpdate(); } catch (Exception $e) { $errors["unread"] = $e->getMessage(); } } else { if (isset($_POST["sent"])) { $form = "sent"; $to = Tools::prepareUserArgString($_POST["email"]); $subject = Tools::prepareUserArgString($_POST["subject"]); $texte = Tools::prepareUserArgString($_POST["message"]); if (!Tools::verifyEmail($to)) { $errors["email"] = "Invalid email format"; } else { if (User::findByEmail($to) == null) { $errors["email"] = "Unknow email address"; } else { try { $message = Message::create($subject, $texte, Session::getSessionEmail(), $to); } catch (Exception $e) { $errors["other"] = $e->getMessage(); } } } } else { if (isset($get)) { if (Tools::isStringValid($get) && isGetType($type)) {
/** * * @param string $email * @param string $password * @param string $right * @param boolean $actif */ public static function create($email, $password, $right, $actif) { // Vérifie que les champs soit du bon format. if (!Tools::isStringValid($email) || !Tools::isStringValid($password) || !Tools::isStringValid($right) || !Tools::isBooleanValid($actif)) { throw new Exception("Invalid user arguments type."); } // Vérifie s'il s'agit d'un email. if (!Tools::verifyEmail($email)) { throw new Exception("Invalid email format."); } // Vérifie que l'utilisateur n'existe pas déjà. if (User::findByEmail($email) != null) { throw new Exception("Invalid email, user already exist."); } // Crée un nouvel utilisateur. $user = new User(); // Récupère le droit utilisateur. $user->right = Right::findByName($right); if ($user->right == null) { throw new Exception("Invalid right."); } // Set les autres paramètres $user->id = null; $user->email = $email; $user->photo = ""; $user->salt = Tools::randomSalt(); $user->password = Tools::doHash($password, $user->salt); $user->actif = $actif; try { // Effectue une connexion à la DB. $pdo = DBconnect(); // Commence la transaction. $pdo->beginTransaction(); // Prépare la requête. $stmt = $pdo->prepare("INSERT INTO t_user(email, password, salt, actif, fk_right) VALUES (:email, :password, :salt, :actif, :fk_right)"); $stmt->bindParam(":email", $user->email); $stmt->bindParam(":password", $user->password); $stmt->bindParam(":salt", $user->salt); $stmt->bindParam(":actif", $user->actif); $stmt->bindParam(":fk_right", $user->right->getId()); if ($stmt->execute()) { $pdo->commit(); } else { throw new Exception(); } } catch (Exception $e) { // Revient en arrière si une erreur c'est produite. $pdo->rollBack(); // Envoie à nouveau une exception. throw new Exception("Create user aborted , an error occurated."); } finally { // Ferme le traitement. $stmt->closeCursor(); // Ferme la connexion vers la base de donnée. $pdo = null; } }
/** * * @param string $subject * @param string $texte * @param string $sender * @param string $receiver */ public static function create($subject, $texte, $sender, $receiver) { // Vérifie que les champs soit du bon format. if (!Tools::isStringValid($subject) || !Tools::isStringValid($texte) || !Tools::isStringValid($sender) || !Tools::isStringValid($receiver)) { throw new Exception("Invalid user arguments type."); } // Vérifie s'il s'agit d'un email. if (!Tools::verifyEmail($sender)) { throw new Exception("Invalid sender email format."); } // Vérifie s'il s'agit d'un email. if (!Tools::verifyEmail($receiver)) { throw new Exception("Invalid receiver email format."); } // Vérifie que l'utilisateur existe. $su = User::findByEmail($sender); if ($su == null) { throw new Exception("Invalid email sender."); } // Vérifie que l'utilisateur existe. $ru = User::findByEmail($receiver); if ($ru == null) { throw new Exception("Invalid email receiver."); } try { // Effectue une connexion à la DB. $pdo = DBconnect(); // Commence la transaction. $pdo->beginTransaction(); // Prépare la requête. $stmt = $pdo->prepare("INSERT INTO t_message(subject, message, fk_sender, fk_receiver)\n\t\t\t\t\tVALUES (:subject, :message, :sender, :receiver)"); $stmt->bindParam(":subject", $subject); $stmt->bindParam(":message", $texte); $stmt->bindParam(":sender", $su->getId()); $stmt->bindParam(":receiver", $ru->getId()); if ($stmt->execute()) { $pdo->commit(); } else { throw new Exception(); } } catch (Exception $e) { // Revient en arrière si une erreur c'est produite. $pdo->rollBack(); // Envoie à nouveau une exception. throw new Exception("Create message aborted, an error occurated."); } finally { // Ferme le traitement. $stmt->closeCursor(); // Ferme la connexion vers la base de donnée. $pdo = null; } }