aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/class/controllerconnect.php12
-rw-r--r--app/class/controlleruser.php2
-rw-r--r--app/class/modeluser.php17
-rw-r--r--app/class/user.php37
-rw-r--r--app/view/templates/user.php39
-rw-r--r--assets/css/home.css8
-rw-r--r--assets/css/terminal.css4
-rw-r--r--composer.json2
8 files changed, 92 insertions, 29 deletions
diff --git a/app/class/controllerconnect.php b/app/class/controllerconnect.php
index 303abf2..bf1b72d 100644
--- a/app/class/controllerconnect.php
+++ b/app/class/controllerconnect.php
@@ -37,11 +37,13 @@ class Controllerconnect extends Controller
if (isset($_POST['pass'])) {
$this->user = $this->usermanager->passwordcheck($_POST['pass']);
if($this->user != false) {
- $this->usermanager->connectcounter($this->user);
- $this->usermanager->writesession($this->user);
- $_SESSION['workspace']['showleftpanel'] = true;
- $_SESSION['workspace']['showrightpanel'] = false;
-
+ if($this->user->expiredate() === false || $this->user->level() === 10 || $this->user->expiredate('date') > $this->now) {
+ $this->user->connectcounter();
+ $this->usermanager->add($this->user);
+ $this->usermanager->writesession($this->user);
+ $_SESSION['workspace']['showleftpanel'] = true;
+ $_SESSION['workspace']['showrightpanel'] = false;
+ }
}
}
if ($id !== null) {
diff --git a/app/class/controlleruser.php b/app/class/controlleruser.php
index 78daa04..d56d999 100644
--- a/app/class/controlleruser.php
+++ b/app/class/controlleruser.php
@@ -13,7 +13,7 @@ class Controlleruser extends Controller
$getuser = $this->usermanager->get($this->user);
if($this->user->isadmin()) {
$userlist = $this->usermanager->getlister();
- $this->showtemplate('user', ['userlist' => $userlist, 'getuser' => $getuser]);
+ $this->showtemplate('user', ['userlist' => $userlist, 'getuser' => $getuser, 'now' => $this->now->format('Y-m-d')]);
} else {
$this->showtemplate('user', ['getuser' => $getuser]);
}
diff --git a/app/class/modeluser.php b/app/class/modeluser.php
index ed8b254..7d14f95 100644
--- a/app/class/modeluser.php
+++ b/app/class/modeluser.php
@@ -50,6 +50,9 @@ class Modeluser extends Modeldb
+ /**
+ * @return array list of User objects
+ */
public function getlister()
{
$userlist = [];
@@ -177,20 +180,6 @@ class Modeluser extends Modeldb
$this->repo->delete($user->id());
}
- /**
- * Incerment connection counter
- *
- * @param string|User $id
- *
- * @return bool
- */
- public function connectcounter($id)
- {
- $user = $this->get($id);
- $user->connectcounter();
- return $this->add($user);
- }
-
}
diff --git a/app/class/user.php b/app/class/user.php
index 7a05f7b..ba3dfea 100644
--- a/app/class/user.php
+++ b/app/class/user.php
@@ -10,6 +10,7 @@ class User
protected $cookie = 0;
protected $columns = ['title', 'datemodif', 'datecreation', 'secure', 'visitcount'];
protected $connectcount = 0;
+ protected $expiredate = false;
public function __construct($datas = [])
{
@@ -85,6 +86,33 @@ class User
return $this->connectcount;
}
+ public function expiredate(string $type = 'string')
+ {
+ if ($type == 'string') {
+ if(!empty($this->expiredate)) {
+ return $this->expiredate->format('Y-m-d');
+ } else {
+ return false;
+ }
+ } elseif ($type == 'date') {
+ if(!empty($this->expiredate)) {
+ return $this->expiredate;
+ } else {
+ return false;
+ }
+ } elseif ($type == 'hrdi') {
+ if(empty($this->expiredate)) {
+ return 'never';
+ } else {
+ $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
+ if($this->expiredate < $now) {
+ return 'expired';
+ } else {
+ return hrdi($this->expiredate->diff($now));
+ }
+ }
+ }
+ }
// _______________________ S E T _______________________
@@ -148,6 +176,15 @@ class User
}
}
+ public function setexpiredate($expiredate)
+ {
+ if ($expiredate instanceof DateTimeImmutable) {
+ $this->expiredate = $expiredate;
+ } else {
+ $this->expiredate = DateTimeImmutable::createFromFormat('Y-m-d', $expiredate, new DateTimeZone('Europe/Paris'));
+ }
+ }
+
diff --git a/app/view/templates/user.php b/app/view/templates/user.php
index 7512267..4717ee6 100644
--- a/app/view/templates/user.php
+++ b/app/view/templates/user.php
@@ -16,17 +16,26 @@
<h1>User : <?= $user->id() ?></h1>
+<h2>Infos</h2>
+
+
+<p>Connections count : <?= $getuser->connectcount() ?></p>
+
+<p>Account will expire in : <?= $getuser->expiredate('hrdi') ?></p>
-<form action="<?= $this->url('userpref') ?>" method="post">
<h2>Preferences</h2>
-<input type="number" name="cookie" value="<?= $getuser->cookie() ?>" id="cookie" min="0" max="365">
-<label for="cookie">Cookie conservation time <i>(In days)</i></label>
-<input type="submit" value="submit">
+<form action="<?= $this->url('userpref') ?>" method="post">
+<p>
+ <input type="number" name="cookie" value="<?= $getuser->cookie() ?>" id="cookie" min="0" max="365">
+ <label for="cookie">Cookie conservation time <i>(In days)</i></label>
+ <input type="submit" value="submit">
+</p>
+
</form>
</article>
@@ -40,7 +49,7 @@
<table>
<tr>
-<th>id</th><th>password</th><th>hash</th><th>level</th><th>action</th>
+<th>id</th><th>password</th><th>hash</th><th>level</th><th>set expiration date</th><th>action</th><th>expire</th>
</tr>
<tr>
@@ -67,8 +76,14 @@
</select>
</td>
<td>
+ <input type="date" name="expiredate" id="expiredate" min="<?= $now ?>">
+ </td>
+ <td>
<input type="submit" value="add">
</td>
+ <td>
+
+ </td>
</form>
</tr>
@@ -102,6 +117,13 @@ foreach ($userlist as $user ) {
</select>
</td>
+
+ <td>
+ <input type="date" name="expiredate" id="expiredate"<?= $user->expiredate() !== false ? 'value="' . $user->expiredate('string') . '"' : '' ?>>
+ <span>reset<input type="checkbox" name="expiredate" id="expiredate" value="null"></span>
+
+ </td>
+
<td>
<input type="hidden" name="id" value="<?= $user->id() ?>">
<input type="submit" name="action" value="update">
@@ -110,6 +132,13 @@ foreach ($userlist as $user ) {
</td>
+
+
+ <td>
+ <?= $user->expiredate('hrdi') ?>
+ </td>
+
+
</tr>
<?php
diff --git a/assets/css/home.css b/assets/css/home.css
index 928b34b..8d43330 100644
--- a/assets/css/home.css
+++ b/assets/css/home.css
@@ -75,6 +75,8 @@ p {
}
+
+
tr:hover {
background-color: grey;
color: white;
@@ -120,7 +122,7 @@ main.admin input, select, textarea {
}
main section {
- max-width: 800px;
+ width: fit-content;
margin: 1%;
}
@@ -304,6 +306,10 @@ main.user table form {
display: inline-block;
}
+main.user td {
+ white-space: nowrap;
+}
+
diff --git a/assets/css/terminal.css b/assets/css/terminal.css
index ae26ff0..1ab9408 100644
--- a/assets/css/terminal.css
+++ b/assets/css/terminal.css
@@ -15,12 +15,12 @@ body {
}
div#topbar, article#main, main.media div, main.home div#options, main.info nav, main article, h1, h2, main.info article h4, textarea, input {
- background:transparent;
+ background:black;
border-color: white;
}
.editor div#leftbar, .editor #edittopbar, .editor div#rightbar, details, .editor .tabs {
- background:transparent;
+ background:black;
border-color: white;
}
diff --git a/composer.json b/composer.json
index 3491541..f66f519 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "w-cms",
"description": "point'n think",
- "version": "1.2.9",
+ "version": "1.3.0",
"require": {
"michelf/php-markdown": "^1.8",
"league/plates": "3.*",