<?php
class Signup extends Controller {

    private $userModel;

    public function __construct() {
        $this->userModel = $this->logic('LoginModel');
    }

    public function index() {
        $this->display('auth/signup');
    }

    public function create() {
        $name  = $_POST['name'];
        $email = $_POST['email'];
        $pass1 = $_POST['password'];
        $pass2 = $_POST['confirm'];

        if ($pass1 !== $pass2) {
            $_SESSION['error'] = "Password doesn't match!";
            header("Location: /signup");
            exit;
        }

        $hash = password_hash($pass1, PASSWORD_DEFAULT);

        $this->userModel->createUser($name, $email, $hash);

        header("Location: /login");
    }
}
