<?php
require_once(__DIR__ . '/../Class/class.user.php');

$userClass = new Class_user($pdo);
if (isset($_POST['login']) && isset($_POST['password'])) {
	//Récupère les données de l'utilisateur
	$data = $userClass->connectUser($_POST['login'], $_POST['password']);

	if ($data == false) {
		header('location: index.php');
	}


	//Si l'utilisateur existe ou pas
	if (count($data) === 0) {
		header('location: index.php?direction=connexion&msg=errorco');
	} else {
		$_SESSION['uId'] = $data['uId'];
		$_SESSION['uNom'] = $data['uNom'];
		$_SESSION['uPrenom'] = $data['uPrenom'];
		$_SESSION['uAdresse'] = $data['uAdresse'];
		$_SESSION['uCp'] = $data['uCp'];
		$_SESSION['uVille'] = $data['uVille'];
		$_SESSION['uSecteur'] = $data['uSecteur'];
		$_SESSION['uLabo'] = $data['uLabo'];
		$_SESSION['uType'] = $data['pLibelle'];

		header('location: index.php?direction=home');
	}
} else {
	include('vues/v_connexion.php');
}
