Skip to content

Commit

Permalink
bugs fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
bertugfahriozer committed Nov 23, 2023
1 parent 69883f3 commit c1a1fe4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public function initController(RequestInterface $request, ResponseInterface $res
// E.g.: $this->session = \Config\Services::session();
$this->commonModel = new CommonModel();
$this->ci4msseoLibrary = new Ci4msseoLibrary();
$this->defData = ['settings' => (object)cache('settings'), 'menus' => $this->commonModel->lists('menu', '*', [], 'queue ASC')];
$this->defData = ['settings' => (object)cache('settings'), 'menus' => $this->commonModel->lists('menu', '*', [], 'queue ASC'), 'agent'=>$this->request->getUserAgent()];
}
}
2 changes: 1 addition & 1 deletion modules/Backend/Controllers/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function templateSelectPost()
if ($this->commonModel->edit('settings',
['content' => json_encode(['path' => $this->request->getPost('path'),
'name' => $this->request->getPost('name')], JSON_UNESCAPED_UNICODE)],
['opiton' => 'templateInfos'])) {
['option' => 'templateInfos'])) {
cache()->delete('settings');
return $this->response->setJSON(['result' => true]);
} else return $this->response->setJSON(['result' => false]);
Expand Down
26 changes: 12 additions & 14 deletions modules/Backend/Libraries/AuthLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,11 @@ public function attempt(array $credentials, bool $remember = null): bool

$this->user = $this->validate($credentials, true);
$falseLogin = $this->commonModel->selectOne('auth_logins', ['ip_address' => $this->ipAddress], '*', 'id DESC');
$settings=cache('settings');
$settings = (object)json_decode(array_reduce($settings, fn($carry, $item) => $carry ?? ('locked' == $item->option ? $item : null))->content, true);
$settings=(object)cache('settings');

// Kalan deneme hakkı hesaplanıyor.
if ($falseLogin && $falseLogin->isSuccess === false) {
if ($falseLogin->counter && ((int)$falseLogin->counter + 1) >= (int)$settings->try) $falseCounter = -1;
if ($falseLogin->counter && ((int)$falseLogin->counter + 1) >= (int)$settings->locked->try) $falseCounter = -1;
else $falseCounter = $falseLogin->counter;
} else $falseCounter = null;

Expand Down Expand Up @@ -381,9 +380,8 @@ public function generateActivateHash()
/* if return is true user blocked else login active */
public function isBlockedAttempt($username): bool
{
$settings=cache('settings');
$settings = (object)json_decode(array_reduce($settings, fn($carry, $item) => $carry ?? ('locked' == $item->option ? $item : null))->content, true);
if ($settings->isActive) {
$settings=(object)cache('settings');
if ($settings->locked->isActive) {
$whitelist = $this->commonModel->selectOne('login_rules', ['type' => 'whitelist']);
if ($whitelist) {
foreach ($whitelist->username as $locked_username)
Expand Down Expand Up @@ -415,7 +413,7 @@ public function isBlockedAttempt($username): bool
if (!$countLocked) $countLockedValue = 0;
else $countLockedValue = $countLocked->counter;

if ((int)$settings->record <= $countLockedValue) {
if ((int)$settings->locked->record <= $countLockedValue) {
$this->commonModel->edit('locked', ['id' => $countLocked->id], ['counter' => 0]);
return false;
}
Expand All @@ -430,9 +428,9 @@ public function isBlockedAttempt($username): bool

$loginAttempts = $this->userModel->getOneOr('auth_logins', ['isSuccess' => false], 'id DESC', 'id,counter', $where_or);

if ($loginAttempts && isset($loginAttempts->counter) && ($loginAttempts->counter + 1) >= (int)$settings->try) {
if (($countLockedValue + 1) < ((int)$settings->record))
$expiry_date = Time::createFromFormat('Y-m-d H:i:s', $this->now->addMinutes((int)$settings->min));
if ($loginAttempts && isset($loginAttempts->counter) && ($loginAttempts->counter + 1) >= (int)$settings->locked->try) {
if (($countLockedValue + 1) < ((int)$settings->locked->record))
$expiry_date = Time::createFromFormat('Y-m-d H:i:s', $this->now->addMinutes((int)$settings->locked->min));
else {
$countLockedValue = -1;
$expiry_date = Time::createFromFormat('Y-m-d H:i:s', $this->now->addMinutes(1440)); // 24 hours ago
Expand Down Expand Up @@ -500,10 +498,9 @@ public function ip2long_vX($ip)
public function remainingEntryCalculation()
{
$falseLogin = $this->commonModel->selectOne('auth_logins', ['ip_address' => $this->ipAddress], '*', 'id DESC');
$settings=cache('settings');
$settings = (object)json_decode(array_reduce($settings, fn($carry, $item) => $carry ?? ('locked' == $item->option ? $item : null))->content, true);
if ($falseLogin) return (int)$settings->try - (int)$falseLogin->counter - 1;
else return (int)$settings->try - 1;
$settings=(object)cache('settings');
if ($falseLogin) return (int)$settings->locked->try - (int)$falseLogin->counter - 1;
else return (int)$settings->locked->try - 1;
}

public function has_perm(string $module, string $method = ''): bool
Expand All @@ -516,6 +513,7 @@ public function has_perm(string $module, string $method = ''): bool
return $item['className'] === $searchValues[0] && $item['methodName'] === $searchValues[1];
});
$perms = reset($perms);
//dd($perms['typeOfPermissions']);
$typeOfPermissions = (array)json_decode($perms['typeOfPermissions']);
$intersect = array_intersect_assoc($typeOfPermissions, $perms);
if(!empty($intersect)) return true;
Expand Down

0 comments on commit c1a1fe4

Please sign in to comment.