Browse Source
was talking to a friend, and she made the good point that a variation upon a tune creates a new tune oh, also started on user accounts lolmaster
12 changed files with 228 additions and 72 deletions
@ -0,0 +1,10 @@ |
|||
<?php |
|||
|
|||
namespace App\Enumerators; |
|||
|
|||
enum SessionElement: string |
|||
{ |
|||
case IS_LOGGED_IN = "IS_LOGGED_IN"; |
|||
case USER_ID = "USER_ID"; |
|||
case USERNAME = "USERNAME"; |
|||
} |
@ -0,0 +1,10 @@ |
|||
<?php |
|||
|
|||
use App\Wrappers\TwigWrapper; |
|||
|
|||
require_once __DIR__ . "/../vendor/autoload.php"; |
|||
|
|||
TwigWrapper::RenderTwig( |
|||
target: "Pages/login.html.twig", |
|||
arguments: [], |
|||
); |
@ -0,0 +1,26 @@ |
|||
<?php |
|||
|
|||
use App\Enumerators\SessionElement; |
|||
use App\Wrappers\DatabaseInteractions; |
|||
use App\Wrappers\TwigWrapper; |
|||
|
|||
require_once __DIR__ . "/../vendor/autoload.php"; |
|||
|
|||
|
|||
$db = new DatabaseInteractions(); |
|||
|
|||
$yourTunes = $db->RunSelect( |
|||
queryBuilder: \App\Wrappers\SQLQueryBuilderWrapper::SELECT( |
|||
table: 'Tunes' |
|||
) |
|||
->where(cond: 'T.CreatedBy LIKE :__user_id__') |
|||
->bindValue(name: '__user_id__', value: $_SESSION[SessionElement::USER_ID->value]) |
|||
); |
|||
|
|||
TwigWrapper::RenderTwig( |
|||
target: "Pages/profile.html.twig", |
|||
arguments: [ |
|||
"YourTunes" => $yourTunes, |
|||
"YourDances" => [], |
|||
], |
|||
); |
@ -0,0 +1,45 @@ |
|||
<?php |
|||
|
|||
use App\Enumerators\SessionElement; |
|||
use App\Wrappers\DatabaseInteractions; |
|||
use App\Wrappers\SQLQueryBuilderWrapper; |
|||
|
|||
require_once __DIR__ . "/../../vendor/autoload.php"; |
|||
|
|||
$username = $_POST['Username']; |
|||
$password = $_POST['Password']; |
|||
|
|||
|
|||
$sha512Hash = hash(algo: 'sha512', data: $password, binary: false); |
|||
$hashedPassword = password_hash(password: $sha512Hash, algo: PASSWORD_BCRYPT); |
|||
|
|||
$db = new DatabaseInteractions(); |
|||
|
|||
$result = $db->RunSelect( |
|||
queryBuilder: SQLQueryBuilderWrapper::SELECT( |
|||
table: 'Users' |
|||
) |
|||
->where(cond: 'T.Username LIKE :__username__') |
|||
->bindValue(name: '__username__', value: $username) |
|||
->limit(limit: 1) |
|||
); |
|||
|
|||
if(sizeof($result) != 1) |
|||
{ |
|||
echo "invalid user"; |
|||
die(); |
|||
} |
|||
|
|||
$result = $result[0]; |
|||
|
|||
if (!password_verify($sha512Hash, $result['PasswordHash'])) |
|||
{ |
|||
echo "invalid password"; |
|||
die(); |
|||
} |
|||
|
|||
$_SESSION[SessionElement::IS_LOGGED_IN->value] = true; |
|||
$_SESSION[SessionElement::USER_ID->value] = $result['ID']; |
|||
$_SESSION[SessionElement::USERNAME->value] = $result['Username']; |
|||
|
|||
header("Location: /"); |
@ -0,0 +1,25 @@ |
|||
{% extends "/Bases/StandardWebPage.html.twig" %} |
|||
|
|||
{% block content %} |
|||
<div class="InnerContent"> |
|||
<h1>Ceilidh Kit Login</h1> |
|||
<form |
|||
action="/FormHandling/Login.php" |
|||
method="POST" |
|||
> |
|||
<label for="Username">{{ "Username"|translate }}</label> |
|||
<br> |
|||
<input id="Username" name="Username" type="text"> |
|||
|
|||
<br> |
|||
|
|||
<label for="Password">{{ "Password"|translate }}</label> |
|||
<br> |
|||
<input id="Password" name="Password" type="password"> |
|||
|
|||
<br> |
|||
|
|||
<input type="submit"> |
|||
</form> |
|||
</div> |
|||
{% endblock %} |
@ -0,0 +1,48 @@ |
|||
{% extends "/Bases/StandardWebPage.html.twig" %} |
|||
|
|||
{% block content %} |
|||
<div class="InnerContent"> |
|||
<h1>{{ "Your Profile"|translate }}</h1> |
|||
|
|||
<div class="DLContainer"> |
|||
<h2>{{ "Summary"|translate }}</h2> |
|||
<dl> |
|||
<dt>{{ "User ID"|translate }}</dt> |
|||
<dd>{{ _SESSION_.USER_ID }}</dd> |
|||
|
|||
<dt>{{ "Username"|translate }}</dt> |
|||
<dd>{{ _SESSION_.USERNAME }}</dd> |
|||
</dl> |
|||
</div> |
|||
|
|||
<h2>{{ "Your Tunes"|translate }}</h2> |
|||
<table> |
|||
<thead> |
|||
<tr> |
|||
<th>{{ "Title"|translate }}</th> |
|||
<th>{{ "Created At"|translate }}</th> |
|||
<th>{{ "Copyright"|translate }}</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{% for tuneDetails in YourTunes %} |
|||
<tr> |
|||
<td><a href="/tune/{{ tuneDetails.ID }}">{{ tuneDetails.Title }}</a></td> |
|||
<td>{{ tuneDetails.CreatedAt }}</td> |
|||
<td>{{ tuneDetails.Copyright }}</td> |
|||
</tr> |
|||
{% endfor %} |
|||
</tbody> |
|||
</table> |
|||
|
|||
<h2>{{ "Your Dances"|translate }}</h2> |
|||
<table> |
|||
<thead> |
|||
<tr> |
|||
<th>{{ "Title"|translate }}</th> |
|||
<th>{{ "Created At"|translate }}</th> |
|||
</tr> |
|||
</thead> |
|||
</table> |
|||
</div> |
|||
{% endblock %} |
Loading…
Reference in new issue