mmicastres / sae301-Thomas-Zabalo

Creation d'une application web en utilisant la techno TWIG
https://zabalo.alwaysdata.net/
0 stars 1 forks source link

Connexion #1

Open Thomas-Zabalo opened 9 months ago

Thomas-Zabalo commented 9 months ago
Thomas-Zabalo commented 9 months ago

Dans phpmyadmin pour mettre les noms en majuscules

UPDATE SAE301_Utilsateur
SET `Nom` = UPPER(Nom);

Twig

{% extends 'index.html.twig' %}

{% block section %}
  <section class="p-5 bg-indigo d-flex">
    <div class="container-fluid h-custom">
      <div class="row d-flex justify-content-center align-items-center h-100">
        <div class="col-md-9 col-lg-6 col-xl-5">
          <img src="img/login.png" class="img-fluid" alt="Sample image" />
        </div>
        <div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1">
          <div class="mb-5">
            <h2 class="fw-bold mb-2 text-uppercase text-center text-white">MOODLE MMI</h2>
            <h4 class="mb-2 text-center text-white">Connexion</h4>
          </div>
          <form method="post" action="index.php">
            <!-- Email input -->
            <div class="form-outline mb-4">
              <label class="form-label text-white" for="form3Example3">Adresse mail</label>
              <input type="text" id="login" class="form-control form-control-lg rounded-pill bg-white" name="login" placeholder="Entrez votre adresse mail IUT" />
            </div>

            <!-- Password input -->
            <div class="form-outline mb-3">
              <label class="form-label text-white" for="form3Example4">Mot de passe</label>
              <input type="password" id="passwd" class="form-control form-control-lg rounded-pill bg-white" name="passwd" placeholder="Entrer votre mot de passe" value="" />
            </div>

            <div class="d-flex justify-content-between align-items-center">
              <!-- Checkbox -->
              <div>
                <input type="checkbox" onclick="myFunction()" />
                <label class="form-check-label text-white" for="form2Example3">Voir le mot de passe</label>
              </div>
              <div>
                <a href="" class="underline text-white">Mot de passe oublié ?</a>
              </div>
            </div>
            <div class="d-flex justify-content-between align-items-center my-5">
              <a href="?action=inscription" class="underline text-white">Créer un compte</a>
              <input type="submit" name="connexion" value="connexion" class="btn btn-primary btn-lg" style="padding-left: 2.5rem; padding-right: 2.5rem" />
            </div>
          </form>
        </div>
      </div>
    </div>
  </section>
  <div><a href="" class="indigo-200 nav-link">Retour</a></div>
{% endblock %}

Index.php

if (isset($_GET["action"])  && $_GET["action"] == "login") {
  $memController->membreFormulaire();
}

MembreManager.php

public function verif_identification($login, $password)
    {
        //echo $login." : ".$password;
        $req = "SELECT Id_Utilisateur, nom, prenom FROM SAE301_Utilisateur WHERE Mail=:login and mot_de_passe=:password";
        $stmt = $this->_db->prepare($req);
        $stmt->execute(array(":login" => $login, ":password" => $password));
        if ($data = $stmt->fetch()) {
            $membre = new Membre($data);
            return $membre;
        } else {
            echo "L'utilisateur n'a pas été trouvé.";
        }
    }

MembreController.php

    {
        // verif du login et mot de passe
        // if ($_POST['login']=="user" && $_POST['passwd']=="pass")
        $login = htmlspecialchars($_POST['login']);
        $passwd = htmlspecialchars($_POST['passwd']);
        $membre = $this->membreManager->verif_identification($login, $passwd);
        if ($membre != false) { // acces autorisé : variable de session acces = oui
            $_SESSION['acces'] = "oui";
            $_SESSION['idmembre'] = $membre->idUtilisateur();
            $message = "Bonjour " . $membre->prenom() . " " . $membre->nom() . "!";
            echo $this->twig->render('index.html.twig', array('acces' => $_SESSION['acces'], 'message' => $message));
        } else { // acces non autorisé : variable de session acces = non
            $message = "identification incorrecte";
            $_SESSION['acces'] = "non";
            echo $this->twig->render('index.html.twig', array('acces' => $_SESSION['acces'], 'message' => $message));
        }
    }