Browse Source

can now change your password

master
Cerys 4 weeks ago
parent
commit
1896b28416
  1. 3
      Localisation/en-GB.yaml
  2. 10
      Pages/change-password.php
  3. 38
      Public/FormHandling/ChangePassword.php
  4. 3
      Routing/Router.php
  5. 39
      Templates/Pages/change-password.html.twig
  6. 1
      Templates/Pages/profile.html.twig

3
Localisation/en-GB.yaml

@ -18,6 +18,8 @@ Bars: Bars
##################################################
# C
##################################################
Change Password: Change Password
Confirm New Password: Confirm New Password
Confirm Password: Confirm Password
Copyright: Copyright
Create an Account: Create an Account
@ -93,6 +95,7 @@ Logout: Logout
##################################################
# N
##################################################
New Password: New Password
Number of Parts: Number of Parts

10
Pages/change-password.php

@ -0,0 +1,10 @@
<?php
use App\Wrappers\TwigWrapper;
require_once __DIR__ . "/../vendor/autoload.php";
TwigWrapper::RenderTwig(
target: "Pages/change-password.html.twig",
arguments: [],
);

38
Public/FormHandling/ChangePassword.php

@ -0,0 +1,38 @@
<?php
use App\Enumerators\SessionElement;
use App\Wrappers\CAPTCHAWrapper;
use App\Wrappers\DatabaseInteractions;
use App\Wrappers\SessionWrapper;
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['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();
$db->RunUpdate(
queryBuilder: SQLQueryBuilderWrapper::UPDATE(
table: 'Users',
)
->set(col: 'PasswordHash', value: ':__password_hash__')
->where('ID=:__user_id__')
->bindValue(name: '__user_id__', value: SessionWrapper::Get(SessionElement::USER_ID))
->bindValue(name: '__password_hash__', value: $hashedPassword)
);
header("Location: /profile");
die();

3
Routing/Router.php

@ -30,6 +30,9 @@ switch($requestElements[0])
case "logout":
require_once __DIR__ . '/../Pages/logout.php';
return true;
case "change-password":
require_once __DIR__ . '/../Pages/change-password.php';
return true;
case "profile":
require_once __DIR__ . '/../Pages/profile.php';
return true;

39
Templates/Pages/change-password.html.twig

@ -0,0 +1,39 @@
{% extends "/Bases/StandardWebPage.html.twig" %}
{% block content %}
<script src="https://www.google.com/recaptcha/enterprise.js?render={{ _CAPTCHA_KEY_ID_ }}"></script>
<script>
function onSubmitChangePasswordForm(token) {
document.getElementById("ChangePasswordForm").submit();
}
</script>
<div class="InnerContent">
<h1>{{ "Change Password"|translate }}</h1>
<form
id="ChangePasswordForm"
action="/FormHandling/ChangePassword.php"
method="POST"
>
<label for="Password1">{{ "New Password"|translate }}</label>
<br>
<input id="Password1" name="Password1" type="password">
<br>
<label for="Password2">{{ "Confirm New Password"|translate }}</label>
<br>
<input id="Password2" name="Password2" type="password">
<br>
<button class="g-recaptcha"
data-sitekey="{{ _CAPTCHA_KEY_ID_ }}"
data-callback='onSubmitChangePasswordForm'
data-action='submit'>{{ "Change Password"|translate }}</button>
</form>
</div>
{% endblock %}

1
Templates/Pages/profile.html.twig

@ -5,6 +5,7 @@
<h1>{{ "Your Profile"|translate }}</h1>
<a href="/logout">{{ "Logout"|translate }}</a>
<a href="/change-password">{{ "Change Password"|translate }}</a>
<div class="DLContainer">
<h2>{{ "Summary"|translate }}</h2>

Loading…
Cancel
Save