Exemplo n.º 1
0
function register()
{
    error_log('\\nregister\\n', 3, '/var/tmp/php.log');
    $request = Slim::getInstance()->request();
    $user = json_decode($request->getBody());
    if (checkUserExist($user->email) != 0) {
        echo '{"id":"0"}';
        return;
    }
    $sql = "INSERT INTO user (id, name, email, password, phoneNumber, sex, debug) VALUES (:id, :name, :email, :password, :phoneNumber,  :sex, :debug)";
    try {
        $db = getConnection();
        $stmt = $db->prepare($sql);
        $stmt->bindParam("id", $user->id);
        $stmt->bindParam("name", $user->name);
        $stmt->bindParam("email", $user->email);
        $stmt->bindParam("password", $user->password);
        $stmt->bindParam("phoneNumber", $user->phoneNumber);
        $stmt->bindParam("sex", $user->sex);
        $stmt->bindParam("debug", $user->debug);
        $stmt->execute();
        $user->id = $db->lastInsertId();
        $db = null;
        echo json_encode($user);
    } catch (PDOException $e) {
        error_log($e->getMessage(), 3, '/var/tmp/php.log');
        echo '{"error":{"text":' . $e->getMessage() . '}}';
    }
}
Exemplo n.º 2
0
            <div class="col-md-4">
                <h1 class="text-center text-success">Connexion</h1>
                <br>

                <?php 
    if (!isset($_POST['emailConnexion'])) {
        //premiere fois sur la page de connexion
        include __DIR__ . '/../vues/formulaireConnexion.php';
    } else {
        // clik sur le bouton de soumission du formulaire de connexion
        //recupération des données
        $emailConnexion = securiserSaisie($_POST['emailConnexion']);
        $motDePasseConnexion = securiserSaisie($_POST['motDePasseConnexion']);
        // controle des donnees
        if (!checkUserExist($emailConnexion, $motDePasseConnexion)) {
            ?>
                        <div class="alert alert-danger alert-dismissable">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <strong>Email</strong> ou <strong>mot de passe</strong> incorrect
                        </div>
                        <?php 
            include __DIR__ . '/../vues/formulaireConnexion.php';
        } else {
            // connexion réussie
            $_SESSION['user'] = selectPseudonyme($emailConnexion, $motDePasseConnexion);
            header('location: index.php?p=user');
        }
    }
    ?>
Exemplo n.º 3
0
/**
 *if all input field filled correctly, password=password confirmation, and email address does not stored yet, call saveNewUser() which inserts to db
 */
function register()
{
    global $connection;
    $name = mysqli_real_escape_string($connection, $_POST['name']);
    $email = mysqli_real_escape_string($connection, $_POST['email']);
    $phone = mysqli_real_escape_string($connection, $_POST['phone']);
    $password = mysqli_real_escape_string($connection, $_POST['pass']);
    $confirm_password = mysqli_real_escape_string($connection, $_POST['confirm_pass']);
    if (empty($name) || empty($phone) || empty($email) || empty($password) || empty($confirm_password)) {
        header('Location:add_user.php?error=1');
    } elseif ($password !== $confirm_password) {
        header('Location:add_user.php?error=2');
    } elseif (checkUserExist($email)) {
        header('Location:add_user.php?error=3');
    } else {
        saveNewUser($name, $email, $phone, $password);
    }
}