-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a page to view last authentications attempts
- Loading branch information
1 parent
286d875
commit dbf3b43
Showing
15 changed files
with
274 additions
and
10 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
website/app-templates/smarty/elements/user_authentication_history_as_list.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{if $authentications.subset} | ||
{foreach from=$authentications.subset item=authentication} | ||
<tr class="{if !$authentication->succeed}danger{else}success{/if}"> | ||
<td> | ||
{if $authentication->succeed}{t}Success{/t}{else}{t}Failure{/t}{/if} | ||
</td> | ||
<td> | ||
{$authentication->method} | ||
</td> | ||
<td> | ||
{$authentication->created_on_datetime|print_date_iso_format nofilter} | ||
</td> | ||
<td> | ||
{$authentication->ip} | ||
</td> | ||
<td> | ||
{$authentication->user_agent} | ||
</td> | ||
</tr> | ||
{/foreach} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
website/app-templates/smarty/pages/user_authentication_history.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{extends file='base.tpl'} | ||
|
||
{block name=title}🙋 {t}Authentication history{/t}{/block} | ||
|
||
{\Assets::instance()->addCss(GK_CDN_DATATABLE_CSS) && ''} | ||
{\Assets::instance()->addJs(GK_CDN_DATATABLE_JS) && ''} | ||
|
||
{include file='macros/pagination.tpl'} | ||
{block name=content} | ||
<a class="anchor" id="results"></a> | ||
|
||
<h2>🙋 {t}Authentication history{/t}</h2> | ||
<div class="row"> | ||
<div class="col-xs-12 col-md-9"> | ||
|
||
{if $authentications_count} | ||
<div class="table-responsive"> | ||
<table id="userAuthenticationHistory" class="table table-striped" style="width:100%"> | ||
<thead> | ||
<tr> | ||
<th>{t}Status{/t}</th> | ||
<th>{t}Method{/t}</th> | ||
<th>{t}Date{/t}</th> | ||
<th>{t}IP Address{/t}</th> | ||
<th>{t}User-Agent{/t}</th> | ||
</tr> | ||
</thead> | ||
<tbody></tbody> | ||
</table> | ||
</div> | ||
{else} | ||
|
||
<em>{t}No activity yet!{/t}</em> | ||
|
||
{/if} | ||
|
||
</div> | ||
<div class="col-xs-12 col-md-3"> | ||
{* {include file='blocks/user/actions.tpl'}*} | ||
</div> | ||
</div> | ||
|
||
{/block} | ||
|
||
{include file='macros/datatable.tpl'} | ||
{block name=javascript} | ||
$('#userAuthenticationHistory').dataTable({ | ||
{call common alias='user_authentication_history'} | ||
"searching": false, | ||
"order": [[ 2, 'desc' ]], | ||
"columns": [ | ||
{ "name": "succeed" }, | ||
{ "name": "method" }, | ||
{ "name": "created_on_datetime" }, | ||
{ "name": "ip" }, | ||
{ "name": "user_agent" } | ||
], | ||
}); | ||
{/block} |
21 changes: 21 additions & 0 deletions
21
website/app-templates/smarty/plugins/modifier.print_date_iso_format.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use Carbon\Carbon; | ||
|
||
/** | ||
* Smarty plugin | ||
* ------------------------------------------------------------- | ||
* File: modifier.print_date_iso_format.php | ||
* Type: modifier | ||
* Name: print_date_iso_format | ||
* Purpose: outputs a date time as isoformat | ||
* -------------------------------------------------------------. | ||
*/ | ||
function smarty_modifier_print_date_iso_format(DateTime $date, string $isoFormat = 'lll', string $format = 'c'): string { | ||
return sprintf( | ||
'<span data-datetime="%s" title="%s">%s</span>', | ||
$date->format($format), | ||
$date->format($format), | ||
Carbon::parse($date->format('c'))->isoFormat($isoFormat) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
website/app/GeoKrety/Controller/Pages/BaseDatatableUserAuthenticationHistory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace GeoKrety\Controller; | ||
|
||
use GeoKrety\Model\UsersAuthenticationHistory; | ||
|
||
abstract class BaseDatatableUserAuthenticationHistory extends BaseDatatable { | ||
protected function getObject(): \GeoKrety\Model\Base { | ||
return new UsersAuthenticationHistory(); | ||
} | ||
|
||
protected function getObjectName(): string { | ||
return 'authentications'; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
protected function getSearchable(): array { | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
website/app/GeoKrety/Controller/Pages/UserAuthenticationHistory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace GeoKrety\Controller; | ||
|
||
use CurrentUserLoader; | ||
use GeoKrety\Model\UsersAuthenticationHistory; | ||
use GeoKrety\Service\Smarty; | ||
|
||
class UserAuthenticationHistory extends BaseDatatableUserAuthenticationHistory { | ||
use CurrentUserLoader; | ||
|
||
public function get(\Base $f3) { | ||
$authentications_count = new UsersAuthenticationHistory(); | ||
Smarty::assign('authentications_count', $authentications_count->count($this->getFilter())); | ||
Smarty::render('pages/user_authentication_history.tpl'); | ||
} | ||
|
||
protected function getFilter(): array { | ||
return ['username = ?', $this->currentUser->username]; | ||
} | ||
|
||
protected function getTemplate(): string { | ||
return 'elements/user_authentication_history_as_list.tpl'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.