<?php
	session_start();

	if (isset($_POST)) {
			
	//Contiene las variables de configuracion para conectar a la base de datos
	include "../config/config.php";
	include_once "../../lib/Helper/PasswordHelper.php";

	$email=mysqli_real_escape_string($con,(strip_tags($_POST["email"],ENT_QUOTES)));
	$password=isset($_POST["password"]) ? (string) $_POST["password"] : "";

    $query = mysqli_query($con,"SELECT * FROM user WHERE email =\"$email\" OR username=\"$email\"");

		if ($row = mysqli_fetch_array($query)) {
			if (!PasswordHelper::verify($password, $row['password'])) {
				header('Location: ../index.php?alert=1');
				return;
			}

			PasswordHelper::upgrade($con, $row['id'], $password, $row['password']);

				$_SESSION['admin_id'] = $row['id'];
				header("location: ../?view=dashboard");
				

		}else{
			header("Location: ../index.php?alert=1");
		}
	}else{
		header("location: ../");
	}

?>
