Browse Source

can now create accounts

master
Cerys 4 weeks ago
parent
commit
dd90aa65ff
  1. 61
      Public/FormHandling/CreateAccount.php
  2. 3
      Routing/Router.php
  3. 3
      composer.json
  4. 2
      composer.lock

61
Public/FormHandling/CreateAccount.php

@ -0,0 +1,61 @@
<?php
use App\Enumerators\SessionElement;
use App\Wrappers\CAPTCHAWrapper;
use App\Wrappers\DatabaseInteractions;
use App\Wrappers\SQLQueryBuilderWrapper;
use Ramsey\Uuid\Uuid;
require_once __DIR__ . "/../../vendor/autoload.php";
$captchaResponse = $_POST['g-recaptcha-response'];
CAPTCHAWrapper::HandleCaptchaResponse($captchaResponse);
if(!isset($_POST['Username'])) die('No username');
if(!isset($_POST['Password1'])) die('No password');
if(!isset($_POST['Password2'])) die('No confirm password');
if($_POST['Password1'] != $_POST['Password2']) die('Passwords do not match');
$sha512Hash = hash(algo: 'sha512', data: $_POST['Password1'], binary: false);
$hashedPassword = password_hash(password: $sha512Hash, algo: PASSWORD_BCRYPT);
$db = new DatabaseInteractions();
$existingUser = $db->RunSelect(
queryBuilder: SQLQueryBuilderWrapper::SELECT(
table: 'Users'
)
->where(cond: 'T.Username LIKE :__username__')
->bindValue(name: '__username__', value: $_POST['Username'])
->limit(limit: 1)
);
if (!empty($existingUser)) {
echo "Username already exists. Please choose a different username.";
die();
}
$userID = Uuid::uuid4()->toString();
$db->RunInsert(
queryBuilder: SQLQueryBuilderWrapper::INSERT(
table: 'Users',
)
->set(col: 'ID', value: ':__user_id__')
->set(col: 'Username', value: ':__username__')
->set(col: 'PasswordHash', value: ':__password_hash__')
->bindValue(name: '__user_id__', value: $userID)
->bindValue(name: '__username__', value: $_POST['Username'])
->bindValue(name: '__password_hash__', value: $hashedPassword)
);
$_SESSION[SessionElement::IS_LOGGED_IN->value] = true;
$_SESSION[SessionElement::USER_ID->value] = $userID;
$_SESSION[SessionElement::USERNAME->value] = $_POST['Username'];
header("Location: /profile");
die();

3
Routing/Router.php

@ -2,11 +2,12 @@
use App\Configuration; use App\Configuration;
use App\Enumerators\SessionElement; use App\Enumerators\SessionElement;
use App\Wrappers\SessionWrapper;
use App\Wrappers\TwigWrapper; use App\Wrappers\TwigWrapper;
require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../vendor/autoload.php";
session_start(); SessionWrapper::Start();
// Get the request URI and break it into segments // Get the request URI and break it into segments
$requestUri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH); $requestUri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);

3
composer.json

@ -29,6 +29,7 @@
"ext-pdo": "*", "ext-pdo": "*",
"aura/sqlquery": "2.8.1", "aura/sqlquery": "2.8.1",
"google/cloud-recaptcha-enterprise": "v1.7.0" "google/cloud-recaptcha-enterprise": "v1.7.0",
"ramsey/uuid": "*"
} }
} }

2
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "efea1a83885c04fe988e656c653f9f65", "content-hash": "d9cebd28c0a5216d94784b6216be8d80",
"packages": [ "packages": [
{ {
"name": "algolia/algoliasearch-client-php", "name": "algolia/algoliasearch-client-php",

Loading…
Cancel
Save