
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
declare(strict_types=1);
require __DIR__ . '/BaseController.php';

class AuthController extends BaseController {
  public function login(): void {
    if (isset($_GET['lang'])) set_lang(current_lang());

    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
      csrf_check();
      $email = trim($_POST['email'] ?? '');
      $pass = (string)($_POST['password'] ?? '');
      if (login($this->pdo, $email, $pass)) {
        flash_set('success', 'Welcome');
        redirect(base_url($this->config, '/index.php?r=dashboard/index'));
      }
      flash_set('danger', 'Invalid credentials');
    }
    $this->render('auth/login.php', []);
  }

  public function logout(): void {
    logout();
    redirect(base_url($this->config, '/index.php?r=auth/login'));
  }
}
