37 lines
		
	
	
		
			917 B
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			917 B
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
<?php
 | 
						|
 | 
						|
if (session_status() == PHP_SESSION_NONE) {
 | 
						|
    session_start();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
if(isset($_POST["login"], $_POST["pw"]))
 | 
						|
{
 | 
						|
  try {
 | 
						|
      $config = include('../config.php');
 | 
						|
      $bdd = new PDO('mysql:host='.$config['host'].';dbname='.$config['dbName'].';charset=utf8', $config['username'], $config['pw']);
 | 
						|
  } catch (Exception $e) {
 | 
						|
      die('Erreur : '.$e->getMessage());
 | 
						|
  }
 | 
						|
  $req = $bdd->prepare('SELECT * FROM projetphp WHERE login = ? AND mot_de_passe = ?');
 | 
						|
  $req->execute(array(htmlspecialchars($_POST["login"]),md5($_POST["pw"])));
 | 
						|
  if($req->rowCount() > 0)
 | 
						|
  {
 | 
						|
    $data = $req->fetch();
 | 
						|
    $_SESSION["login"] = $data["login"];
 | 
						|
    $_SESSION["sl"] = $data["security_level"];
 | 
						|
    echo json_encode((object)array("login"=>true));
 | 
						|
  }
 | 
						|
  else
 | 
						|
    echo json_encode((object)array("login"=>false));
 | 
						|
}
 | 
						|
elseif(isset($twig)) {
 | 
						|
  $template = $twig->load('login.html.twig');
 | 
						|
 | 
						|
 | 
						|
  echo $template->render(array());
 | 
						|
}
 | 
						|
 | 
						|
?>
 |