From 1878d156fd10a3e9d8f25b40b297f20af2f2c23a Mon Sep 17 00:00:00 2001 From: Bye Date: Tue, 29 Oct 2024 17:59:36 +0000 Subject: [PATCH] Auto stash before merge of "rewrite" and "origin/rewrite" --- .DS_Store | Bin 0 -> 8196 bytes common/account_utils.php | 11 +++++-- common/app_utils.php | 10 ++++++ common/misc.php | 10 +++++- common/strings.php | 18 +++++++---- common/validation.php | 26 ++++++++++++++++ index.php | 26 ++++++++++------ views/.DS_Store | Bin 0 -> 6148 bytes views/admin/dashboard.php | 38 +++++++++++++++++++++++ views/login.php | 11 +++++-- views/oauth_login.php | 63 ++++++++++++++++++++++++++++++++++++++ views/partials/footer.php | 3 +- views/partials/header.php | 3 ++ views/settings_region.php | 20 ++++++++++-- 14 files changed, 215 insertions(+), 24 deletions(-) create mode 100644 .DS_Store create mode 100644 common/app_utils.php create mode 100644 views/.DS_Store create mode 100644 views/admin/dashboard.php create mode 100644 views/oauth_login.php diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8d6c3b80b07f99a14e1c7fc0fb183fdc393acc4a GIT binary patch literal 8196 zcmeHM%W4!s6uqUL$)KC4kVFJ&HHje)CHUI5Vcd$4RS+T0gGpd|ddy5Rh#h9w95RqElX|51W6Hygi z+lliS3Yzxoo@;09%nYnTK6TnFYmFrCUwOYNC z)G=4Rzc}~i`tpy5zQ1{_zqjdp8@TZvsWb-MEoxGWo_omZ@@?PiVn;vUejF|_wv!(x zBlO}34_|%L_!VkULNR^`bv*{Od?D+1Im~=`eGnTC-Wo28vKWsC@u!ji3bgU-`yA*O zI2`$0{4Y1xzwckM`rBL=yU6e3@>_D8`cPmSd(fjn7CqPmdM3i<(7N`jpN7mK7d6_8 z@+hBA2rxz)FrRK-jZ5SC2$#?7vvccr%${gI&N{9#%626_9wG9SHEWc zE|-h-z2EN^SQ~E*mq}SnA&*@!=;BF9XxqC-o<8`*JRHBv}xYSrq!NBD>ESKZ3 eM}HXNIz*_>iL6bH#SEH!2w)jx5C#6J0)GMB9TnyP literal 0 HcmV?d00001 diff --git a/common/account_utils.php b/common/account_utils.php index d68de02..831c574 100644 --- a/common/account_utils.php +++ b/common/account_utils.php @@ -1,5 +1,7 @@ $text, 'type' => $type]; } + +function show_flash(array $flash) { + $output = '
    '; + foreach ($flash as $item) { + $output .= '
  • '. $item['text'] .'
  • '; + } + return $output; +} diff --git a/common/strings.php b/common/strings.php index 0fb0606..2a8f26f 100644 --- a/common/strings.php +++ b/common/strings.php @@ -12,20 +12,26 @@ const LANGAUGES = [ 'flag' => 'usa' ], [ - 'code' => 'en_UWU', - 'name' => 'Cute English', - 'flag' => 'owo' + 'code' => 'fi', + 'name' => 'suomi' ], [ 'code' => 'ga', - 'name' => 'Irish', + 'name' => 'Gaeilge', 'flag' => 'ie' ], [ 'code' => 'nb_NO', - 'name' => 'Norwegian Bokmål', + 'name' => 'Norsk bokmål', 'flag' => 'no' - ] + ], + + // Joke languages + [ + 'code' => 'en_UWU', + 'name' => 'Cute English', + 'flag' => 'owo' + ], ]; function get_string($key="generic.generic", $substitutes=[]) { diff --git a/common/validation.php b/common/validation.php index ef5ede1..c9b1afa 100644 --- a/common/validation.php +++ b/common/validation.php @@ -1,5 +1,31 @@ "; + if ($echo) echo $output; + else return $output; +} + +function validate_csfr($token = null): bool +{ + $token = $token ?: $_REQUEST['CSFR_TOKEN']; + + if ($_SESSION['CSFR_TOKEN'] == $token) { + return true; + } + + return false; +} + function validate_email($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); } diff --git a/index.php b/index.php index e3b96ff..426e5b9 100644 --- a/index.php +++ b/index.php @@ -28,6 +28,7 @@ require_once 'common/strings.php'; require_once 'common/validation.php'; require_once 'common/database.php'; require_once 'common/account_utils.php'; +require_once 'common/app_utils.php'; require_once 'common/files.php'; require_once 'common/misc.php'; @@ -88,21 +89,25 @@ patch_lang($_SESSION['lang']); $routes = [ - '' => function () { require 'views/home.php'; }, + '' => function () { global $user; require 'views/home.php'; }, 'admin' => function () { - global $path, $query, $DOC_ROOT, $flash; + global $path, $query, $DOC_ROOT, $flash, $user; requires_auth(); requires_admin(); - switch ($path[2]) { - default: return 404; - case 'files': - require 'views/admin/files.php'; + if (key_exists(2, $path)) { + switch ($path[2]) { + default: return 404; + case 'files': + require 'views/admin/files.php'; + } + } else { + require 'views/admin/dashboard.php'; } }, 'api' => function () { - global $path, $query; + global $path, $query, $user; unset($path[1]); $path = array_values($path); @@ -110,7 +115,7 @@ $routes = [ require 'api.php'; /* Handoff further routing to API script. */ }, 'auth' => function () { - global $path, $query, $flash; + global $path, $query, $flash, $user; switch ($path[2]) { case 'signout': @@ -122,6 +127,9 @@ $routes = [ case 'login': require 'views/login.php'; break; + case 'oauth': + require 'views/oauth_login.php'; + break; default: return 404; } @@ -162,7 +170,7 @@ $routes = [ return 200; }, 'settings' => function () { - global $path, $flash, $user; + global $path, $flash, $user, $query; if (isset($path[2])) { switch ($path[2]) { default: return 404; diff --git a/views/.DS_Store b/views/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6698d514e1b49aba5438005b0733d1b395947f25 GIT binary patch literal 6148 zcmeHK%}T^T3{KV+sv_)BZ*vww_64La^)B=QbbmmF))xQHy$im8kK)~@@C|$kzf8iq z-L85QSrW*6(@Zi=zYa}9L_B(!4T%Oslt2Z0TNqY|tc!M}XBJuHxW`R#In1Y3S$BNh z@IM)lcehDnno&vDwDkVAU)!r?m1UEnn!uWz=g0d;hi@m#9Z`>Q5)h8VRU?C2 zx<>|MD(J3#iguq?`7Gx0{_*_yau9Rr>{V7@8U5tf&g)F_a&ZQn0cT)c89>bzNp=){ zbOxLOXJF2Nd>;Z-Fg0ux + + + + + + [A] Dashboard ~> ByeCorps ID + + + +
    +

    [ADMIN] Dashboard

    + + + +
    + + + diff --git a/views/login.php b/views/login.php index b497655..8666c50 100644 --- a/views/login.php +++ b/views/login.php @@ -10,6 +10,11 @@ if ($_SESSION['auth']) { } if ($_SERVER['REQUEST_METHOD'] == 'POST') { + if (!validate_csfr()) { + flash(get_string('error.generic'), $flash); + goto skip; + } + // Validate email address if (!validate_email($_POST['email'])) { $error_body = get_string('error.invalidEmail'); @@ -67,13 +72,15 @@ skip: if (isset($subtitle)) { echo '

    '. $subtitle .'

    '; } - ?> - +