Add profile page

This commit is contained in:
Jay Trees 2022-03-23 10:33:04 +01:00
parent 55e1d158d6
commit d0b20f5736
3 changed files with 42 additions and 9 deletions

View file

@ -8,6 +8,7 @@ $(function() {
$('.ui.form').form({
fields: {
'user-email' : 'email',
'user-password' : ['minLength[8]', 'empty'],
match : {
identifier : 'user-password-repeat',
depends : 'user-password',

View file

@ -124,7 +124,8 @@ switch ($step) {
`password_reset_token` VARCHAR(128) NULL DEFAULT NULL,
`password_reset_valid_until` DATETIME NOT NULL DEFAULT NOW(),
`last_login` DATETIME NOT NULL DEFAULT NOW(),
`power` INT NOT NULL DEFAULT 0
`power` INT NOT NULL DEFAULT 0,
`birthdate` DATE NULL DEFAULT NULL
);');
$database->query('CREATE INDEX `idx_password` ON `users` (`password`);');

View file

@ -6,7 +6,32 @@
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
use wishthis\Page;
use wishthis\{Page, User};
if (isset($_POST['user-id'])) {
$set = array();
if (!empty($_POST['user-email'])) {
$set[] = '`email` = "' . $_POST['user-email'] . '"';
}
if (!empty($_POST['user-password']) && !empty($_POST['user-password-repeat'])) {
$set[] = '`password` = "' . User::generatePassword($_POST['user-password']) . '"';
}
if (!empty($_POST['user-birthdate'])) {
$set[] = '`birthdate` = "' . date('Y-m-d', strtotime($_POST['user-birthdate'])) . '"';
}
$database
->query('UPDATE `users`
SET ' . implode(',', $set) . '
WHERE `id` = ' . $_POST['user-id']);
session_destroy();
header('Location: /?page=home');
die();
}
$page = new Page(__FILE__, __('Profile'));
$page->header();
@ -19,7 +44,9 @@ $page->navigation();
<h1 class="ui header"><?= $page->title ?></h1>
<div class="ui segment">
<form class="ui form">
<form class="ui form" method="POST">
<input type="hidden" name="user-id" value="<?= $user->id ?>" />
<div class="field">
<label><?= __('Email') ?></label>
@ -46,7 +73,11 @@ $page->navigation();
<div class="ui calendar">
<div class="ui input left icon">
<i class="calendar icon"></i>
<input type="text" placeholder="<?= __('Pick a date') ?>" />
<input type="text"
name="user-birthdate"
placeholder="<?= __('Pick a date') ?>"
value="<?= $user->birthdate ?>"
/>
</div>
</div>
</div>