<?php
	declare(strict_types = 1);
	namespace Kimendisch\Sbgg_Jetzt;
	use Flake\Url_Redirect;
	use Flake\Csrf;
	
	if(isset($_POST["token"])){
		// VERIFY CSRF TOKEN //
		Csrf::check();
		
		
		// CHECK TOKEN //
		// collect token from form submit
		$token = $_POST["token"];
		
		// load token hash from env
		$auth_token_hash = Env::ADMIN_AREA["auth_token_hash"];
		
		// check
		$token_valid = password_verify($token, $auth_token_hash);
		
		
		// MAYBE DO LOGIN //
		if($token_valid){
			// set session flag
			$_SESSION[__NAMESPACE__]["admin"]["login"] = true;
			
			// reload page
			Url_Redirect::query_modify(remove: ["login_failure"]);
		}
		
		
		// LOGIN FAILED //
		// display feedback after reload
		Url_Redirect::query_modify(remove: ["login_failure"], add: ["login_failure"]);
	}
?>
