From 49f827b172dd3c07e3c4562a261557feb1ef03f6 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Fri, 9 Aug 2019 02:56:29 +0200 Subject: Feature : Users may expire - user have expiredate - admins can set up this date --- app/class/controllerconnect.php | 12 +++++++----- app/class/controlleruser.php | 2 +- app/class/modeluser.php | 17 +++-------------- app/class/user.php | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 20 deletions(-) (limited to 'app/class') 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')); + } + } + -- cgit v1.2.3