From bb315f3efb049d3177fa8027e57df4f4f83084cc Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Fri, 31 Dec 2021 18:15:08 -0600 Subject: [PATCH] User registration added to menus and page tree. --- .gitignore | 1 + kanga.world/assets/css/main.css | 5 +- .../content/{home => 1_home}/comingsoon.png | 0 .../{home => 1_home}/comingsoon.png.txt | 0 kanga.world/content/{home => 1_home}/home.txt | 0 .../{home => 1_home}/kanga-original.png | 0 .../{home => 1_home}/kanga-original.png.txt | 0 .../content/{home => 1_home}/kangaworld.png | 0 .../{home => 1_home}/kangaworld.png.txt | 0 .../{home => 1_home}/kangaworldlogo.png | 0 .../{home => 1_home}/onlinegamingnetwork.png | 0 .../onlinegamingnetwork.png.txt | 0 kanga.world/content/activated/activated.txt | 5 + kanga.world/content/newuser/newuser.txt | 5 + kanga.world/content/user/user.txt | 7 +- .../site/blueprints/pages/activated.yml | 7 ++ kanga.world/site/blueprints/pages/newuser.yml | 7 ++ kanga.world/site/config/config.php.example | 4 +- kanga.world/site/controllers/register.php | 21 ++-- .../site/plugins/download-kirbytag/index.php | 101 ++++++++++-------- kanga.world/site/snippets/header.php | 2 +- kanga.world/site/snippets/menu.php | 35 +++++- kanga.world/site/templates/activated.php | 12 +++ kanga.world/site/templates/newuser.php | 12 +++ 24 files changed, 160 insertions(+), 64 deletions(-) rename kanga.world/content/{home => 1_home}/comingsoon.png (100%) rename kanga.world/content/{home => 1_home}/comingsoon.png.txt (100%) rename kanga.world/content/{home => 1_home}/home.txt (100%) rename kanga.world/content/{home => 1_home}/kanga-original.png (100%) rename kanga.world/content/{home => 1_home}/kanga-original.png.txt (100%) rename kanga.world/content/{home => 1_home}/kangaworld.png (100%) rename kanga.world/content/{home => 1_home}/kangaworld.png.txt (100%) rename kanga.world/content/{home => 1_home}/kangaworldlogo.png (100%) rename kanga.world/content/{home => 1_home}/onlinegamingnetwork.png (100%) rename kanga.world/content/{home => 1_home}/onlinegamingnetwork.png.txt (100%) create mode 100644 kanga.world/content/activated/activated.txt create mode 100644 kanga.world/content/newuser/newuser.txt create mode 100644 kanga.world/site/blueprints/pages/activated.yml create mode 100644 kanga.world/site/blueprints/pages/newuser.yml create mode 100644 kanga.world/site/templates/activated.php create mode 100644 kanga.world/site/templates/newuser.php diff --git a/.gitignore b/.gitignore index d0ab042..f600f1b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ kanga.world/composer.json kanga.world/index.php kanga.world/site/config/config.php kanga.world/content/home/*/ +kanga.world/content/1_home/*/ diff --git a/kanga.world/assets/css/main.css b/kanga.world/assets/css/main.css index cab49f2..540a412 100644 --- a/kanga.world/assets/css/main.css +++ b/kanga.world/assets/css/main.css @@ -1,4 +1,7 @@ -a:link:not(.dropdown-item), a:visited:not(.dropdown-item), a:hover:not(.dropdown-item), a:active:not(.dropdown-item) { +a:link:not(.dropdown-item):not(.nav-link), +a:visited:not(.dropdown-item):not(.nav-link), +a:hover:not(.dropdown-item):not(.nav-link), +a:active:not(.dropdown-item):not(.nav-link) { color: #ff0000; } diff --git a/kanga.world/content/home/comingsoon.png b/kanga.world/content/1_home/comingsoon.png similarity index 100% rename from kanga.world/content/home/comingsoon.png rename to kanga.world/content/1_home/comingsoon.png diff --git a/kanga.world/content/home/comingsoon.png.txt b/kanga.world/content/1_home/comingsoon.png.txt similarity index 100% rename from kanga.world/content/home/comingsoon.png.txt rename to kanga.world/content/1_home/comingsoon.png.txt diff --git a/kanga.world/content/home/home.txt b/kanga.world/content/1_home/home.txt similarity index 100% rename from kanga.world/content/home/home.txt rename to kanga.world/content/1_home/home.txt diff --git a/kanga.world/content/home/kanga-original.png b/kanga.world/content/1_home/kanga-original.png similarity index 100% rename from kanga.world/content/home/kanga-original.png rename to kanga.world/content/1_home/kanga-original.png diff --git a/kanga.world/content/home/kanga-original.png.txt b/kanga.world/content/1_home/kanga-original.png.txt similarity index 100% rename from kanga.world/content/home/kanga-original.png.txt rename to kanga.world/content/1_home/kanga-original.png.txt diff --git a/kanga.world/content/home/kangaworld.png b/kanga.world/content/1_home/kangaworld.png similarity index 100% rename from kanga.world/content/home/kangaworld.png rename to kanga.world/content/1_home/kangaworld.png diff --git a/kanga.world/content/home/kangaworld.png.txt b/kanga.world/content/1_home/kangaworld.png.txt similarity index 100% rename from kanga.world/content/home/kangaworld.png.txt rename to kanga.world/content/1_home/kangaworld.png.txt diff --git a/kanga.world/content/home/kangaworldlogo.png b/kanga.world/content/1_home/kangaworldlogo.png similarity index 100% rename from kanga.world/content/home/kangaworldlogo.png rename to kanga.world/content/1_home/kangaworldlogo.png diff --git a/kanga.world/content/home/onlinegamingnetwork.png b/kanga.world/content/1_home/onlinegamingnetwork.png similarity index 100% rename from kanga.world/content/home/onlinegamingnetwork.png rename to kanga.world/content/1_home/onlinegamingnetwork.png diff --git a/kanga.world/content/home/onlinegamingnetwork.png.txt b/kanga.world/content/1_home/onlinegamingnetwork.png.txt similarity index 100% rename from kanga.world/content/home/onlinegamingnetwork.png.txt rename to kanga.world/content/1_home/onlinegamingnetwork.png.txt diff --git a/kanga.world/content/activated/activated.txt b/kanga.world/content/activated/activated.txt new file mode 100644 index 0000000..1976e59 --- /dev/null +++ b/kanga.world/content/activated/activated.txt @@ -0,0 +1,5 @@ +Title: Activation Complete! + +---- + +Text: Your account is now active! Please login. diff --git a/kanga.world/content/newuser/newuser.txt b/kanga.world/content/newuser/newuser.txt new file mode 100644 index 0000000..8a98cb1 --- /dev/null +++ b/kanga.world/content/newuser/newuser.txt @@ -0,0 +1,5 @@ +Title: New User + +---- + +Text: Check your email for an activation link. \ No newline at end of file diff --git a/kanga.world/content/user/user.txt b/kanga.world/content/user/user.txt index ab1d601..8e9603c 100644 --- a/kanga.world/content/user/user.txt +++ b/kanga.world/content/user/user.txt @@ -1,4 +1,4 @@ -Title: User Settings +Title: Profile ---- @@ -26,9 +26,8 @@ Danger: Danger Zone ---- -Delete_Button: Delete Account +Delete-button: Delete Account ---- -Delete_Warning: Are you sure? This action cannot be reversed! - +Delete-warning: Are you sure? This action cannot be reversed! \ No newline at end of file diff --git a/kanga.world/site/blueprints/pages/activated.yml b/kanga.world/site/blueprints/pages/activated.yml new file mode 100644 index 0000000..9ec00f5 --- /dev/null +++ b/kanga.world/site/blueprints/pages/activated.yml @@ -0,0 +1,7 @@ +title: Avtivated User Landing Page +preset: page +fields: + text: + label: Text + type: textarea + size: large diff --git a/kanga.world/site/blueprints/pages/newuser.yml b/kanga.world/site/blueprints/pages/newuser.yml new file mode 100644 index 0000000..65b94b7 --- /dev/null +++ b/kanga.world/site/blueprints/pages/newuser.yml @@ -0,0 +1,7 @@ +title: New User Landing Page +preset: page +fields: + text: + label: Text + type: textarea + size: large diff --git a/kanga.world/site/config/config.php.example b/kanga.world/site/config/config.php.example index 57705e3..071a226 100644 --- a/kanga.world/site/config/config.php.example +++ b/kanga.world/site/config/config.php.example @@ -67,8 +67,8 @@ return [ if ($user = $kirby->users()->findBy('emailActivationToken', $token)) { if ($user->emailActivationToken()->toString() === Str::toType($token, 'string')) { $user->update(['emailActivation' => true]); - go('user'); - //go('CUSTOM_SUCCESSFUL_ACTIVATION_PAGE'); + $kirby->session()->set('kpActivated', true); + go('/activated'); } else { return false; //go('CUSTOM_ERROR_ACTIVATION_PAGE'); diff --git a/kanga.world/site/controllers/register.php b/kanga.world/site/controllers/register.php index 6b6a972..e724af1 100644 --- a/kanga.world/site/controllers/register.php +++ b/kanga.world/site/controllers/register.php @@ -4,8 +4,8 @@ return function ($kirby) { if($kirby->user()) { go('/'); - } - + } + $error = null; $alert = null; @@ -53,14 +53,14 @@ return function ($kirby) { // CHECK EMAIL ACTIVATION if (option('user.email.activation', false) === true) { - + $user->update([ 'emailActivation' => false, 'emailActivationToken' => $token ]); } - $kirby->impersonate(); + $kirby->impersonate(); } catch(Exception $e) { @@ -93,19 +93,18 @@ return function ($kirby) { ]); } - // LOGIN USER - if($user->login($data['password'])) { - go(); - } - + // Welcome new user. + $kirby->session()->set('kpNewUser', true); + go('/newuser'); + $data = []; } } }; - + return [ 'error' => $error, 'alert' => $alert, 'data' => $data ?? false ]; -}; \ No newline at end of file +}; diff --git a/kanga.world/site/plugins/download-kirbytag/index.php b/kanga.world/site/plugins/download-kirbytag/index.php index 1a21008..6e1c78a 100644 --- a/kanga.world/site/plugins/download-kirbytag/index.php +++ b/kanga.world/site/plugins/download-kirbytag/index.php @@ -7,23 +7,30 @@ Kirby::plugin('kangaroopunch/download-kirbytag', [ [ 'pattern' => 'download/(:any)/(:any)', 'action' => function($sourcepage, $filerequested) { - // Unmuddle the page ID that called us. - $slug = str_rot13(urldecode($sourcepage)); - $slug = str_replace('|', '/', $slug); - // Get page object. - $page = kirby()->api()->page($slug); - // Find the current download count. - $file = $page->file($filerequested); - $content = $file->content(); - if ($content->has('downloads')) { - $count = $content->get('downloads')->toInt(); - } else { - // Initialize counter. - $count = 0; + $file = ""; + kirby()->impersonate('kirby'); + try { + // Unmuddle the page ID that called us. + $slug = str_rot13(urldecode($sourcepage)); + $slug = str_replace('|', '/', $slug); + // Get page object. + $page = kirby()->api()->page($slug); + // Find the current download count. + $file = $page->file($filerequested); + $content = $file->content(); + if ($content->has('downloads')) { + $count = $content->get('downloads')->toInt(); + } else { + // Initialize counter. + $count = 0; + } + // Update download count. + $count++; + $file->update([ 'downloads' => $count ]); + } catch (Exception $ex){ + $file = $ex->getMessage(); } - // Update download count. - $count++; - $file->update([ 'downloads' => $count ]); + kirby()->impersonate(); // Send file to user. return $file; } @@ -37,39 +44,45 @@ Kirby::plugin('kangaroopunch/download-kirbytag', [ 'desc' ], 'html' => function($tag) { - // Did we get a valid file? - $file = $tag->file($tag->value()); - if (!$file === true) { - return '
ERROR: Cannot locate "' . $tag->value() . '"!
'; - } - // Ensure we're using the proper blueprint. - //$file->update([ 'template' => 'download' ]); - // Did they provide a description? - if (is_null($tag->desc) === true) { - // No. Does the file itself have one? - $desc = $file->content()->get('description')->value(); - if (is_null($desc) || strlen($desc) == 0) { - // Nope. Use the filename. - $desc = $tag->value(); + try { + // Did we get a valid file? + $file = $tag->file($tag->value()); + if (!$file === true) { + return '
ERROR: Cannot locate "' . $tag->value() . '"!
'; } - } else { - // Yep. Use the provided description. - $desc = $tag->desc; + // Ensure we're using the proper blueprint. + kirby()->impersonate('kirby'); + $file->update([ 'template' => 'download' ]); + kirby()->impersonate(); + // Did they provide a description? + if (is_null($tag->desc) === true) { + // No. Does the file itself have one? + $desc = $file->content()->get('description')->value(); + if (is_null($desc) || strlen($desc) == 0) { + // Nope. Use the filename. + $desc = $tag->value(); + } + } else { + // Yep. Use the provided description. + $desc = $tag->desc; + } + // Find pretty file size. + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + $bytes = max($file->size(), 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + $bytes /= pow(1024, $pow); + $size = round($bytes, 2) . ' ' . $units[$pow]; + // Muddle up the page slug a bit to discourage direct linking to the file. + $slug = str_replace('/', '|', $tag->parent()->id()); + $slug = esc(str_rot13($slug), 'url'); + } catch (Exception $ex) { + return $ex->getMessage(); } - // Find pretty file size. - $units = array('B', 'KB', 'MB', 'GB', 'TB'); - $bytes = max($file->size(), 0); - $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); - $pow = min($pow, count($units) - 1); - $bytes /= pow(1024, $pow); - $size = round($bytes, 2) . ' ' . $units[$pow]; - // Muddle up the page slug a bit to discourage direct linking to the file. - $slug = str_replace('/', '|', $tag->parent()->id()); - $slug = esc(str_rot13($slug), 'url'); // Send the link. return '' . $desc . ' (' . $size . ')'; } ] ] - + ]); diff --git a/kanga.world/site/snippets/header.php b/kanga.world/site/snippets/header.php index 4e75e5c..48352c5 100644 --- a/kanga.world/site/snippets/header.php +++ b/kanga.world/site/snippets/header.php @@ -13,5 +13,5 @@ -
+ diff --git a/kanga.world/site/snippets/menu.php b/kanga.world/site/snippets/menu.php index 18b9c2f..ae66f34 100644 --- a/kanga.world/site/snippets/menu.php +++ b/kanga.world/site/snippets/menu.php @@ -1,12 +1,14 @@ + +

 

diff --git a/kanga.world/site/templates/activated.php b/kanga.world/site/templates/activated.php new file mode 100644 index 0000000..d52d309 --- /dev/null +++ b/kanga.world/site/templates/activated.php @@ -0,0 +1,12 @@ +session()->get('kpActivated') !== true) { + go('/'); + } + + $kirby->session()->remove('kpActivated'); + snippet('header'); +?> + +text()->kirbytext() ?> + + diff --git a/kanga.world/site/templates/newuser.php b/kanga.world/site/templates/newuser.php new file mode 100644 index 0000000..473dd67 --- /dev/null +++ b/kanga.world/site/templates/newuser.php @@ -0,0 +1,12 @@ +session()->get('kpNewUser') !== true) { + go('/'); + } + + $kirby->session()->remove('kpNewUser'); + snippet('header'); +?> + +text()->kirbytext() ?> + +