Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config.yml: added
backend_login_policy
(#5197)
- Loading branch information
Showing
6 changed files
with
126 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* @author mstaab | ||
* | ||
* @package redaxo\core\login | ||
*/ | ||
class rex_login_policy | ||
{ | ||
/** | ||
* @var array<string, int|bool> | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* @param array<string, int|bool> $options | ||
*/ | ||
public function __construct(array $options) | ||
{ | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* @param 'login_tries_1'|'relogin_delay_1'|'login_tries_2'|'relogin_delay_2' $key | ||
*/ | ||
public function getSetting(string $key): int | ||
{ | ||
if (array_key_exists($key, $this->options)) { | ||
return (int) $this->options[$key]; | ||
} | ||
|
||
// defaults, in case config.yml does not define values | ||
// e.g. because of a redaxo core update from a version. | ||
switch ($key) { | ||
case 'login_tries_1': | ||
return 3; | ||
case 'relogin_delay_1': | ||
return 5; | ||
case 'login_tries_2': | ||
return 50; | ||
case 'relogin_delay_2': | ||
return 3600; | ||
} | ||
|
||
throw new rex_exception('Invalid login policy key: ' . $key); | ||
} | ||
|
||
public function isStayLoggedInEnabled(): bool | ||
{ | ||
$key = 'enable_stay_logged_in'; | ||
|
||
if (array_key_exists($key, $this->options)) { | ||
return (bool) $this->options[$key]; | ||
} | ||
|
||
// enabled by default | ||
return true; | ||
} | ||
} |
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