Skip to content

Commit

Permalink
Auth Rules mit Pause funktionierte nicht sinnvoll closes yakamara#487 (
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel authored Aug 29, 2024
1 parent f957ce1 commit 57d9886
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
22 changes: 19 additions & 3 deletions install/tablesets/yform_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,22 @@
"db_type": "",
"list_hidden": 1,
"search": 1,
"name": "last_login_try_time",
"label": "translate:last_login_try_time",
"not_required": "",
"only_empty": "2",
"no_db": "",
"format": "",
"modify_default": ""
},
{
"table_name": "rex_ycom_user",
"prio": 22,
"type_id": "value",
"type_name": "datestamp",
"db_type": "",
"list_hidden": 1,
"search": 1,
"name": "termination_time",
"label": "translate:termination_time",
"not_required": "",
Expand All @@ -342,7 +358,7 @@
},
{
"table_name": "rex_ycom_user",
"prio": 22,
"prio": 23,
"type_id": "value",
"type_name": "integer",
"db_type": "",
Expand All @@ -358,7 +374,7 @@
},
{
"table_name": "rex_ycom_user",
"prio": 23,
"prio": 24,
"type_id": "value",
"type_name": "html",
"db_type": "",
Expand All @@ -371,7 +387,7 @@
},
{
"table_name": "rex_ycom_user",
"prio": 24,
"prio": 25,
"type_id": "value",
"type_name": "be_manager_relation",
"db_type": "",
Expand Down
1 change: 1 addition & 0 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ firstname = Vorname
activation_key = Aktivierungsschlüssel
session_key = Sessionschlüssel
last_login_time = Letzter erfolgreicher Login
last_login_try_time = Letzter versuchter Login
last_action_time = Letzte Aktion
termination_time = Kündigungszeitpunkt
login_failed = Fehlgeschlagene Logins
Expand Down
1 change: 1 addition & 0 deletions lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ firstname = First name
activation_key = Activation key
session_key = Session key
last_login_time = Last sign in
last_login_try_time = Last sign in try
last_action_time = Last action
termination_time = Kündigungszeitpunkt
login_failed = Failed sign in attempts
Expand Down
4 changes: 3 additions & 1 deletion plugins/auth/lib/ycom_auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,15 @@ public static function login(array $params): int
/** @var rex_ycom_user $loginUser */
$loginUser = $loginUsers[0];

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

$loginUser->setValue('last_login_try_time', rex_sql::datetime(time()));

if (
$params['ignorePassword']
|| ('' != $params['loginPassword'] && self::checkPassword($params['loginPassword'], $loginUser->getId()))
Expand Down
7 changes: 4 additions & 3 deletions plugins/auth/lib/ycom_auth_rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ public function check(rex_ycom_user $user, string $rule_name = 'login_try_5_paus

switch ($rule['action']['type']) {
case 'deactivate':
$user->increaseLoginTries();
$user->setValue('status', -2); // to much login failures
$user->save();
return false;
case 'pause':
$lastLoginDate = new DateTime($user->getValue('last_login_time'));
$lastLoginDate->modify('+' . $rule['action']['time'] . ' seconds');
if (date('YmdHis') < $lastLoginDate->format('YmdHis')) {
$lastLoginTryDate = new DateTime($user->getValue('last_login_try_time'));
$lastLoginTryDate->modify('+' . $rule['action']['time'] . ' seconds');
if (date('YmdHis') < $lastLoginTryDate->format('YmdHis')) {
return false;
}
return true;
Expand Down

0 comments on commit 57d9886

Please sign in to comment.