Add power
This commit is contained in:
parent
521ba07b08
commit
fe43855ac3
6 changed files with 79 additions and 72 deletions
|
@ -1,32 +0,0 @@
|
|||
$(function() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
|
||||
var retryIn = urlParams.has('interval') ? urlParams.get('interval') : 5;
|
||||
var value = 0;
|
||||
var total = retryIn * 1000;
|
||||
|
||||
if (!$('.ui.progress').length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$('#retryIn').html(retryIn);
|
||||
|
||||
setTimeout(function step() {
|
||||
$('.ui.progress').progress({
|
||||
total: total,
|
||||
value: value
|
||||
});
|
||||
|
||||
if (value >= total) {
|
||||
setTimeout(function() {
|
||||
urlParams.set('interval', parseInt(retryIn) + 5);
|
||||
|
||||
window.location.href = window.location.origin + '/?' + urlParams.toString();
|
||||
}, 1000);
|
||||
} else {
|
||||
value += 100;
|
||||
|
||||
setTimeout(step, 100);
|
||||
}
|
||||
}, 100)
|
||||
});
|
|
@ -18,13 +18,15 @@ class Page
|
|||
* @param string $filepath The filepath (__FILE__) of the page.
|
||||
* @param string $title The HTML title of the page.
|
||||
*/
|
||||
public function __construct(string $filepath, public string $title = 'wishthis')
|
||||
public function __construct(string $filepath, public string $title = 'wishthis', public int $power = 0)
|
||||
{
|
||||
$this->name = pathinfo($filepath, PATHINFO_FILENAME);
|
||||
|
||||
/**
|
||||
* Session
|
||||
*/
|
||||
global $user;
|
||||
|
||||
$disableRedirect = array(
|
||||
'home',
|
||||
'login',
|
||||
|
@ -35,6 +37,14 @@ class Page
|
|||
header('Location: /?page=login');
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Power
|
||||
*/
|
||||
if ($user->power < $this->power) {
|
||||
header('Location: /?page=power&required=' . $this->power);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function header(): void
|
||||
|
@ -162,7 +172,7 @@ class Page
|
|||
</div>
|
||||
</div>
|
||||
<?php global $options; ?>
|
||||
<?php if ($options->updateAvailable && $user && $user->isLoggedIn()) { ?>
|
||||
<?php if ($options->updateAvailable && $user && 100 === $user->power) { ?>
|
||||
<a class="item" href="/?page=update">
|
||||
<i class="upload icon"></i> Update
|
||||
</a>
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace wishthis;
|
|||
class User
|
||||
{
|
||||
public int $id;
|
||||
public int $power = 0;
|
||||
|
||||
public function __construct(int $id = -1)
|
||||
{
|
||||
|
@ -23,6 +24,18 @@ class User
|
|||
} else {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
if (!isset($this->id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $database;
|
||||
|
||||
$user = $database->query('SELECT * FROM `users`
|
||||
WHERE `id` = ' . $this->id . ';')
|
||||
->fetch();
|
||||
|
||||
$this->power = $user['power'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
32
includes/pages/power.php
Normal file
32
includes/pages/power.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* power.php
|
||||
*
|
||||
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
||||
*/
|
||||
|
||||
use wishthis\Page;
|
||||
|
||||
$page = new page(__FILE__, 'Insufficient power');
|
||||
$page->header();
|
||||
$page->navigation();
|
||||
?>
|
||||
|
||||
<main>
|
||||
<div class="ui container">
|
||||
<h1 class="ui header"><?= $page->title ?></h1>
|
||||
|
||||
<div class="ui segment">
|
||||
<h2 class="ui header">Restricted access</h2>
|
||||
<p>
|
||||
You do not have enough power to view this page.
|
||||
You need <strong><?= $_GET['required'] ?></strong> to see this page, but only have <strong><?= $user->power ?></strong>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
$page->footer();
|
||||
?>
|
|
@ -15,13 +15,13 @@ if (isset($_POST['email'], $_POST['password'])) {
|
|||
|
||||
if (0 === count($users)) {
|
||||
$database->query('INSERT INTO `users`
|
||||
(`email`, `password`) VALUES
|
||||
("' . $_POST['email'] . '", "' . sha1($_POST['password']) . '")
|
||||
(`email`, `password`, `power`) VALUES
|
||||
("' . $_POST['email'] . '", "' . sha1($_POST['password']) . '", 100)
|
||||
;');
|
||||
} else {
|
||||
$database->query('INSERT INTO `users`
|
||||
(`email`, `password`, `power`) VALUES
|
||||
("' . $_POST['email'] . '", "' . sha1($_POST['password']) . '", 100)
|
||||
(`email`, `password`) VALUES
|
||||
("' . $_POST['email'] . '", "' . sha1($_POST['password']) . '")
|
||||
;');
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
use wishthis\{Page, User};
|
||||
|
||||
$page = new page(__FILE__, 'Update');
|
||||
$page = new page(__FILE__, 'Update', 100);
|
||||
$page->header();
|
||||
$page->navigation();
|
||||
|
||||
|
@ -48,42 +48,26 @@ if ('POST' === $_SERVER['REQUEST_METHOD']) {
|
|||
<div class="ui container">
|
||||
<h1 class="ui header"><?= $page->title ?></h1>
|
||||
|
||||
<?php if ($user->isLoggedIn()) { ?>
|
||||
<div class="ui segment">
|
||||
<h2 class="ui header">New version detected</h2>
|
||||
<p>Thank you for updating to <strong>v<?= VERSION ?></strong>!</p>
|
||||
<p>There have been some changes in the database, please run the updater.</p>
|
||||
<div class="ui icon warning message">
|
||||
<i class="exclamation triangle icon"></i>
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
Use at own risk
|
||||
</div>
|
||||
<p>Be sure to make backups before proceeding.</p>
|
||||
<div class="ui segment">
|
||||
<h2 class="ui header">New version detected</h2>
|
||||
<p>Thank you for updating to <strong>v<?= VERSION ?></strong>!</p>
|
||||
<p>There have been some changes in the database, please run the updater.</p>
|
||||
<div class="ui icon warning message">
|
||||
<i class="exclamation triangle icon"></i>
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
Use at own risk
|
||||
</div>
|
||||
</div>
|
||||
<form class="ui form" method="post">
|
||||
<button class="ui orange button" type="submit">
|
||||
<i class="upload icon"></i>
|
||||
Run the updater
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="ui segment">
|
||||
<h2 class="ui header">Maintenance</h2>
|
||||
<p>
|
||||
The administrator of this site is currently running an update.
|
||||
This usually just takes a couple of seconds.
|
||||
</p>
|
||||
<p>
|
||||
Trying again in <span id="retryIn">5</span> seconds...
|
||||
</p>
|
||||
<div class="ui primary progress nolabel">
|
||||
<div class="bar"></div>
|
||||
<p>Be sure to make backups before proceeding.</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<form class="ui form" method="post">
|
||||
<button class="ui orange button" type="submit">
|
||||
<i class="upload icon"></i>
|
||||
Run the updater
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
|
Loading…
Reference in a new issue