<?php
    require_once('models/User.php');

    if ($_SERVER['REQUEST_METHOD'] != 'POST') {
        header('Location: signup.php');
        exit();
    }
    
    if (!isset($_POST['login'], $_POST['passwd'], $_POST['passwdconf'])) {
        header('Location: signup.php');
        exit();
    }
    if (empty($_POST['login']) || empty($_POST['passwd']) || empty($_POST['passwdconf'])) {
        header('Location: signup.php');
        exit();
    }
    
    $login = htmlspecialchars($_POST['login']);
    $passwd = htmlspecialchars($_POST['passwd']);
    $passwdconf = htmlspecialchars($_POST['passwdconf']);
    
    if ($passwd != $passwdconf) {
        header('Location: signup.php');
        exit();
    }

    try {
        $user = new User($login, $passwd);
        $user->create();
        header('Location: signin.php');
        exit();
    }
    catch(Exception $e) {
        exit();
    }
    
    
    
        
