Skip to content

Commit

Permalink
Changes all header locations to redirect helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ssl committed Jan 30, 2023
1 parent 1197128 commit 229e635
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 deletions.
13 changes: 6 additions & 7 deletions app/controllers/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function index()
// Check if posted data is logout
if ($this->getPostValue('logout') !== null) {
$this->session->deleteSession();
header('Location: /manage/account/login');
exit();
redirect('/manage/account/login');
}
} catch (Exception $e) {
$this->view->renderMessage($e->getMessage());
Expand Down Expand Up @@ -102,10 +101,10 @@ public function login()
if (strlen($user['secret']) === 16) {
$user['password'] = $password;
$this->session->createTempSession($user);
header('Location: /manage/account/mfa');
redirect('/manage/account/mfa');
} else {
$this->session->createSession($user);
header('Location: dashboard/index');
redirect('dashboard/index');
}
} catch (Exception $e) {
$this->view->renderMessage($e->getMessage());
Expand All @@ -127,14 +126,14 @@ public function mfa()
$this->view->renderTemplate('account/mfa');

if($this->session->data('temp') != true) {
header('Location: dashboard/index');
redirect('dashboard/index');
exit();
}

if ($this->isPOST()) {
try {
$this->validateCsrfToken();

$username = $this->session->data('username');
$password = $this->session->data('password');
$code = $this->getPostValue('code');
Expand All @@ -146,7 +145,7 @@ public function mfa()
}

$this->session->createSession($user);
header('Location: dashboard/index');
redirect('dashboard/index');
} catch (Exception $e) {
$this->view->renderMessage($e->getMessage());
}
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public function index()
// Make sure the platform is not already installed
try {
$this->model('Setting')->get('version');
header('Location: dashboard/index');
exit();
redirect('dashboard/index');
} catch (Exception $e) {}

if($this->isPOST()) {
Expand Down Expand Up @@ -51,8 +50,7 @@ public function index()
$this->model('User')->create($username, $password, 7);
$user = $this->model('User')->login($username, $password);
$this->session->createSession($user);
header('Location: dashboard/index');
exit();
redirect('dashboard/index');
} catch (Exception $e) {
$this->view->renderMessage($e->getMessage());
}
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public function index()

$payloadList = $this->payloadList();
if (!empty($this->payloadList())) {
header('Location: /manage/payload/edit/' . $payloadList[0]);
exit();
redirect('/manage/payload/edit/' . $payloadList[0]);
}

return $this->showContent();
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public function index()
{
$this->isLoggedInOrExit();

header('Location: /manage/reports/all');
exit();
redirect('/manage/reports/all/');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function index()

// Future updates come here!

header('Location: dashboard/index');
redirect('dashboard/index');
exit();
} catch (Exception $e) {
$this->view->renderMessage($e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function delete($id)
}

$this->model('User')->deleteById($id);
header('Location: /manage/users');
redirect('/manage/users');
}

return $this->showContent();
Expand Down
20 changes: 7 additions & 13 deletions system/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ public function validateSession()
} catch (Exception $e) {
// If session failed to validate, clear the session
$this->session->deleteSession();
header('Location: /manage/account/login');
exit();
redirect('/manage/account/login');
}
}

Expand All @@ -154,8 +153,7 @@ public function isLoggedInOrExit()
{
$this->validateSession();
if (!$this->session->isLoggedIn()) {
header('Location: /manage/account/login');
exit();
redirect('/manage/account/login');
}
}

Expand All @@ -167,8 +165,7 @@ public function isLoggedInOrExit()
public function isLoggedOutOrExit()
{
if ($this->session->isLoggedIn()) {
header('Location: /manage/dashboard/index');
exit();
redirect('/manage/dashboard/index');
}
}

Expand All @@ -181,8 +178,7 @@ public function isAdminOrExit()
{
$this->isLoggedInOrExit();
if (!$this->isAdmin()) {
header('Location: /manage/dashboard/my');
exit();
redirect('/manage/dashboard/my');
}
}

Expand Down Expand Up @@ -244,7 +240,7 @@ private function checkKillSwitch()
if (!empty($killswitch)) {
if ($this->getGetValue('pass') === $killswitch) {
$this->model('Setting')->set('killswitch', '');
header('Location: /');
redirect('/');
} else {
http_response_code(404);
exit();
Expand All @@ -267,8 +263,7 @@ private function checkIfInstalled()
$this->model('Setting')->get('version');
}
} catch (Exception $e) {
header('Location: /manage/install');
exit();
redirect('/manage/install');
}
}

Expand All @@ -287,8 +282,7 @@ private function checkForUpdates()
}
}
} catch (Exception $e) {
header('Location: /manage/update');
exit();
redirect('/manage/update');
}
}
}
12 changes: 12 additions & 0 deletions system/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ function baseDecode($data): string
}
return $result;
}

/**
* Rredirects to location
*
* @param string $location The location
* @return null
*/
function redirect($location)
{
header('Location: ' . $location);
exit();
}
3 changes: 1 addition & 2 deletions system/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public function proccess($uri)
throw new Exception('404');
}
} catch (Exception $e) {
header('Location: /manage/dashboard');
exit();
redirect('/manage/dashboard');
}
$args = isset($parts[4]) ? [$parts[4]] : [];
} else {
Expand Down

0 comments on commit 229e635

Please sign in to comment.