Skip to content

Commit bb64c34

Browse files
committed
Updated Register File
1 parent 52410b2 commit bb64c34

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

example/register.php

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3-
require __DIR__ . "/vendor/autoload.php";
3+
include_once "../vendor/autoload.php";
44
include_once '../src/MY_Framework/Database.php';
5+
include_once '../src/MY_Framework/UserGateway.php';
56

67
use MY_Framework\Database;
8+
use MY_Framework\UserGateway;
79

810
if ($_SERVER["REQUEST_METHOD"] === "POST") {
911

10-
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
12+
$dotenv = Dotenv\Dotenv::createImmutable('../');
1113
$dotenv->load();
1214

1315
$database = new Database(
@@ -17,22 +19,14 @@
1719
$_ENV["DB_PASS"]
1820
);
1921

20-
$sql = "INSERT INTO user (name, username, password_hash, api_key)
21-
VALUES (:name, :username, :password_hash, :api_key)";
22+
$user = new UserGateway($database);
2223

23-
$stmt = $database->prepare($sql);
24-
25-
$password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT);
26-
$api_key = bin2hex(random_bytes(16));
27-
28-
$database->bind(":name", $_POST["name"], PDO::PARAM_STR);
29-
$database->bind(":username", $_POST["username"], PDO::PARAM_STR);
30-
$database->bind(":password_hash", $password_hash, PDO::PARAM_STR);
31-
$database->bind(":api_key", $api_key, PDO::PARAM_STR);
32-
33-
$database->execute();
24+
$api_key = $user->createUser(
25+
$_POST
26+
);
3427

3528
echo "Thank you for registering. Your API key is ", $api_key;
29+
3630
exit;
3731
}
3832

0 commit comments

Comments
 (0)