<?php
	session_regenerate_id();
	global $Route;
	
	require_once $Route->_model;
	$msg = "";
	
	if (isset($_POST['bcusername'])) {
		$a = nettoie_input($_POST['bcusername']);
		$r = nettoie_input($_POST['bcpassword']);
		
		if ((strlen($a) != 0) && (strlen($r) != 0)) {
			$sql = 'SELECT * FROM users WHERE username="' . $a . '" AND active=1;';
			$res = getinfos($sql, "gen");
			if (count($res) == 1) {
				$userLine = $res[0];
				
				if (checkPsswd($r, $userLine["userpswd"])) {
					openSession($userLine);
					eLog("Login Linet de " . $_SESSION['uname']);
					header("Location: /accueil");
					die();
				} else {
					echo "utilisateur non reconnu<br/>";
					$msg = "Identifiant et/ou mot de passe incorrect(s)";
					eLog("Login Admin KO 0 : " . $a . "/" . $r);
				}
				
			} else {
				echo "utilisateur non reconnu<br/>";
				$msg = "Identifiant et/ou mot de passe incorrect(s)";
				eLog("Login Admin KO 1 : " . $a . "/" . $r);
			}
			
		} else {
			eLog("Login Admin KO 2 : " . $a . "/" . $r);
		}
	}
	
	$aView = $aModel;
	require_once $Route->_view;
