header('Location: ../');
}
if (isset($_POST['register'])) {
    $usuario = $_POST['usuario'];
    $email = $_POST['email'];
    $pass = $_POST['pass'];
    $pass2 = $_POST['pass2'];
    if ($pass == $pass2) {
        # Include the Autoloader (see "Libraries" for install instructions)
        //use Mailgun\Mailgun;
        function generate_random_key()
        {
            $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
            $new_key = "";
            for ($i = 0; $i < 32; $i++) {
                $new_key .= $chars[rand(0, 35)];
            }
            return $new_key;
        }
        $random_key = generate_random_key();
        $validated = 0;
        Model::registrarUsuario($usuario, $pass, $email, $random_key, $validated);
        # Instantiate the client.
        $mgClient = new Mailgun('key-116da3f3cd011ad01d454a632a599587');
        $domain = "sandboxe7f47692877a4fd6b2115e79c3ce660d.mailgun.org";
        # Make the call to the client.
        $result = $mgClient->sendMessage("{$domain}", array('from' => 'App-Tracking DW32-IGSR <*****@*****.**>', 'to' => $usuario . ' ' . $email, 'subject' => 'Registro en App-Tracking', 'text' => "Hola {$usuario}!\n                        Gracias por registrarse en nuestro sitio.\n                        Su cuenta ha sido creada, y debe ser activada antes de poder ser utilizada.\n                        Para activar la cuenta, haga click en el siguiente enlace o copielo en la\n                        barra de direcciones del navegador:\n                        https://app-tracking-mongodb-nohtrim.c9.io/model/activate.php?activation=" . $random_key . "&email=" . $email . ""));
        header('Location: ../');
        //echo "registro completado";
    }
}