From c79daae50101ca6e5710e078397ecd94bd00ab66 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 9 Feb 2021 22:56:15 +0100 Subject: [PATCH] impl. todos --- Admin/Install/db.json | 6 ++++++ Controller/BackendController.php | 3 +++ Models/Account.php | 16 ++++++++++++++++ Models/AccountMapper.php | 6 ++++-- Models/GroupMapper.php | 19 +++++++++++++++++++ Theme/Backend/groups-list.tpl.php | 19 ++++++++++++------- 6 files changed, 60 insertions(+), 9 deletions(-) diff --git a/Admin/Install/db.json b/Admin/Install/db.json index c37b46a..850cb97 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -677,6 +677,12 @@ "default": null, "null": true }, + "account_password_temp_limit": { + "name": "account_password_temp_limit", + "type": "DATETIME", + "default": null, + "null": true + }, "account_email": { "name": "account_email", "type": "VARCHAR(70)", diff --git a/Controller/BackendController.php b/Controller/BackendController.php index e60f238..5445de3 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -229,6 +229,9 @@ final class BackendController extends Controller $view->setData('groups', GroupMapper::getAfterPivot(0, null, 25)); } + $memberCount = GroupMapper::countMembers(); + $view->setData('memberCount', $memberCount); + return $view; } diff --git a/Models/Account.php b/Models/Account.php index 7754940..a29e3c6 100755 --- a/Models/Account.php +++ b/Models/Account.php @@ -31,4 +31,20 @@ class Account extends \phpOMS\Account\Account * @since 1.0.0 */ public int $tries = 0; + + /** + * Password. + * + * @var string + * @since 1.0.0 + */ + public string $tempPassword = ''; + + /** + * Remaining login tries. + * + * @var null|\DateTimeImmutable + * @since 1.0.0 + */ + public ?\DateTimeImmutable $tempPasswordLimit = null; } diff --git a/Models/AccountMapper.php b/Models/AccountMapper.php index 6df9ef4..4043016 100755 --- a/Models/AccountMapper.php +++ b/Models/AccountMapper.php @@ -46,6 +46,7 @@ final class AccountMapper extends DataMapperAbstract 'account_name3' => ['name' => 'account_name3', 'type' => 'string', 'internal' => 'name3', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], 'account_password' => ['name' => 'account_password', 'type' => 'string', 'internal' => 'password', 'writeonly' => true], 'account_password_temp' => ['name' => 'account_password_temp', 'type' => 'string', 'internal' => 'tempPassword', 'writeonly' => true], + 'account_password_temp_limit' => ['name' => 'account_password_temp_limit', 'type' => 'DateTimeImmutable', 'internal' => 'tempPasswordLimit'], 'account_email' => ['name' => 'account_email', 'type' => 'string', 'internal' => 'email', 'autocomplete' => true, 'annotations' => ['gdpr' => true]], 'account_tries' => ['name' => 'account_tries', 'type' => 'int', 'internal' => 'tries'], 'account_lactive' => ['name' => 'account_lactive', 'type' => 'DateTime', 'internal' => 'lastActive'], @@ -211,6 +212,8 @@ final class AccountMapper extends DataMapperAbstract } if (!empty($result['account_password_temp']) + && $result['account_password_temp_limit'] !== null + && (new \DateTime('now'))->getTimestamp() < (new \DateTime($result['account_password_temp_limit']))->getTimestamp() && \password_verify($password, $result['account_password_temp'] ?? '') ) { $query->update('account') @@ -227,8 +230,7 @@ final class AccountMapper extends DataMapperAbstract $query->update('account') ->set([ - 'account_lactive' => new \DateTime('now'), - 'account_tries' => $result['account_tries'] + 1, + 'account_tries' => $result['account_tries'] + 1, ]) ->where('account_login', '=', $login) ->execute(); diff --git a/Models/GroupMapper.php b/Models/GroupMapper.php index 2dcf4ce..17504f1 100755 --- a/Models/GroupMapper.php +++ b/Models/GroupMapper.php @@ -16,6 +16,7 @@ namespace Modules\Admin\Models; use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\RelationType; +use phpOMS\DataStorage\Database\Query\Builder; /** * Group mapper class. @@ -108,4 +109,22 @@ final class GroupMapper extends DataMapperAbstract return self::getAllByQuery($query, RelationType::ALL, $depth); } + + public static function countMembers(int $group = 0) : array + { + $query = new Builder(self::$db); + $query->select(self::$hasMany['accounts']['self']) + ->select('COUNT(' . self::$hasMany['accounts']['external'] . ')') + ->from(self::$hasMany['accounts']['table']) + ->groupBy(self::$hasMany['accounts']['self']); + + if ($group !== 0) { + $query->where(self::$hasMany['accounts']['self'], '=', $group); + } + + $result = $query->execute() + ->fetchAll(\PDO::FETCH_KEY_PAIR); + + return $result; + } } diff --git a/Theme/Backend/groups-list.tpl.php b/Theme/Backend/groups-list.tpl.php index b4e77ab..b35c864 100755 --- a/Theme/Backend/groups-list.tpl.php +++ b/Theme/Backend/groups-list.tpl.php @@ -13,12 +13,14 @@ declare(strict_types=1); use phpOMS\Uri\UriFactory; +use phpOMS\Account\GroupStatus; /** * @var \phpOMS\Views\View $this * @var \Modules\Admin\Models\Group[] $groups */ $groups = $this->getData('groups') ?? []; +$memberCount = $this->getData('memberCount') ?? []; $previous = empty($groups) ? '{/prefix}admin/group/list' : '{/prefix}admin/group/list?{?}&id=' . \reset($groups)->getId() . '&ptype=p'; $next = empty($groups) ? '{/prefix}admin/group/list' : '{/prefix}admin/group/list?{?}&id=' . \end($groups)->getId() . '&ptype=n'; @@ -37,17 +39,20 @@ echo $this->getData('nav')->render(); ?> getHtml('Name'); ?> getHtml('Members'); ?> - $value) : ++$c; - $url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/group/settings?{?}&id=' . $value->getId()); - $color = 'darkred'; - if ($value->getStatus() === \phpOMS\Account\GroupStatus::ACTIVE) { $color = 'green'; } - elseif ($value->getStatus() === \phpOMS\Account\GroupStatus::INACTIVE) { $color = 'darkblue'; } - elseif ($value->getStatus() === \phpOMS\Account\GroupStatus::HIDDEN) { $color = 'purple'; } ?> + $value) : ++$c; + $url = UriFactory::build('{/prefix}admin/group/settings?{?}&id=' . $value->getId()); + + $color = 'darkred'; + if ($value->getStatus() === GroupStatus::ACTIVE) { $color = 'green'; } + elseif ($value->getStatus() === GroupStatus::INACTIVE) { $color = 'darkblue'; } + elseif ($value->getStatus() === GroupStatus::HIDDEN) { $color = 'purple'; } + ?> getId(); ?> getHtml('Status'. $value->getStatus()); ?> printHtml($value->name); ?> - + getId()] ?? 0; ?> getHtml('Empty', '0', '0'); ?>