Skip to content

Commit 57d9886

Browse files
authored
Auth Rules mit Pause funktionierte nicht sinnvoll closes #487 (#492)
1 parent f957ce1 commit 57d9886

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

install/tablesets/yform_user.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,22 @@
332332
"db_type": "",
333333
"list_hidden": 1,
334334
"search": 1,
335+
"name": "last_login_try_time",
336+
"label": "translate:last_login_try_time",
337+
"not_required": "",
338+
"only_empty": "2",
339+
"no_db": "",
340+
"format": "",
341+
"modify_default": ""
342+
},
343+
{
344+
"table_name": "rex_ycom_user",
345+
"prio": 22,
346+
"type_id": "value",
347+
"type_name": "datestamp",
348+
"db_type": "",
349+
"list_hidden": 1,
350+
"search": 1,
335351
"name": "termination_time",
336352
"label": "translate:termination_time",
337353
"not_required": "",
@@ -342,7 +358,7 @@
342358
},
343359
{
344360
"table_name": "rex_ycom_user",
345-
"prio": 22,
361+
"prio": 23,
346362
"type_id": "value",
347363
"type_name": "integer",
348364
"db_type": "",
@@ -358,7 +374,7 @@
358374
},
359375
{
360376
"table_name": "rex_ycom_user",
361-
"prio": 23,
377+
"prio": 24,
362378
"type_id": "value",
363379
"type_name": "html",
364380
"db_type": "",
@@ -371,7 +387,7 @@
371387
},
372388
{
373389
"table_name": "rex_ycom_user",
374-
"prio": 24,
390+
"prio": 25,
375391
"type_id": "value",
376392
"type_name": "be_manager_relation",
377393
"db_type": "",

lang/de_de.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ firstname = Vorname
2929
activation_key = Aktivierungsschlüssel
3030
session_key = Sessionschlüssel
3131
last_login_time = Letzter erfolgreicher Login
32+
last_login_try_time = Letzter versuchter Login
3233
last_action_time = Letzte Aktion
3334
termination_time = Kündigungszeitpunkt
3435
login_failed = Fehlgeschlagene Logins

lang/en_gb.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ firstname = First name
2929
activation_key = Activation key
3030
session_key = Session key
3131
last_login_time = Last sign in
32+
last_login_try_time = Last sign in try
3233
last_action_time = Last action
3334
termination_time = Kündigungszeitpunkt
3435
login_failed = Failed sign in attempts

plugins/auth/lib/ycom_auth.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,15 @@ public static function login(array $params): int
211211
/** @var rex_ycom_user $loginUser */
212212
$loginUser = $loginUsers[0];
213213

214+
// Check Only AuthRules
214215
$auth_rules = new rex_ycom_auth_rules();
215216
$authRuleConfig = rex_config::get('ycom/auth', 'auth_rule', 'login_try_5_pause') ?? 'login_try_5_pause';
216217
if (!$auth_rules->check($loginUser, $authRuleConfig)) {
217-
$loginUser->increaseLoginTries()->save();
218218
throw new rex_exception('Login failed - Auth Rules');
219219
}
220220

221+
$loginUser->setValue('last_login_try_time', rex_sql::datetime(time()));
222+
221223
if (
222224
$params['ignorePassword']
223225
|| ('' != $params['loginPassword'] && self::checkPassword($params['loginPassword'], $loginUser->getId()))

plugins/auth/lib/ycom_auth_rules.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ public function check(rex_ycom_user $user, string $rule_name = 'login_try_5_paus
8181

8282
switch ($rule['action']['type']) {
8383
case 'deactivate':
84+
$user->increaseLoginTries();
8485
$user->setValue('status', -2); // to much login failures
8586
$user->save();
8687
return false;
8788
case 'pause':
88-
$lastLoginDate = new DateTime($user->getValue('last_login_time'));
89-
$lastLoginDate->modify('+' . $rule['action']['time'] . ' seconds');
90-
if (date('YmdHis') < $lastLoginDate->format('YmdHis')) {
89+
$lastLoginTryDate = new DateTime($user->getValue('last_login_try_time'));
90+
$lastLoginTryDate->modify('+' . $rule['action']['time'] . ' seconds');
91+
if (date('YmdHis') < $lastLoginTryDate->format('YmdHis')) {
9192
return false;
9293
}
9394
return true;

0 commit comments

Comments
 (0)