impl. todos

This commit is contained in:
Dennis Eichhorn 2021-02-09 22:56:15 +01:00
parent 49d84f4477
commit c79daae501
6 changed files with 60 additions and 9 deletions

View File

@ -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)",

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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(); ?>
<td class="wf-100"><?= $this->getHtml('Name'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td><?= $this->getHtml('Members'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<tbody>
<?php $c = 0; foreach ($groups as $key => $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'; } ?>
<?php $c = 0;
foreach ($groups as $key => $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'; }
?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $value->getId(); ?></a>
<td data-label="<?= $this->getHtml('Status'); ?>"><a href="<?= $url; ?>"><span class="tag <?= $color; ?>"><?= $this->getHtml('Status'. $value->getStatus()); ?></span></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->name); ?></a>
<td data-label="<?= $this->getHtml('Members'); ?>">
<td data-label="<?= $this->getHtml('Members'); ?>"><?= $memberCount[$value->getId()] ?? 0; ?>
<?php endforeach; ?>
<?php if ($c === 0) : ?>
<tr><td colspan="5" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>