diff --git a/public_html/media/js/upload.js b/public_html/media/js/upload.js index 31273151..92176dda 100644 --- a/public_html/media/js/upload.js +++ b/public_html/media/js/upload.js @@ -116,7 +116,7 @@ $(function() } else { - postDom.find('.alert').html(data['errorHtml']).slideDown(); + postDom.find('.alert').html(data['messageHtml']).slideDown(); enableUpload(); } } diff --git a/src/Bootstrap.php b/src/Bootstrap.php index dcb66a0b..fb30c729 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -26,7 +26,7 @@ class Bootstrap ? 'layout-json' : 'layout-normal'; $this->context->transport = new StdClass; - $this->context->transport->success = null; + StatusHelper::init(); AuthController::doLogIn(); @@ -41,29 +41,24 @@ class Bootstrap { $workCallback(); } - catch (SimpleException $e) - { - $this->context->transport->errorMessage = rtrim($e->getMessage(), '.') . '.'; - $this->context->transport->errorHtml = TextHelper::parseMarkdown($this->context->transport->errorMessage, true); - $this->context->transport->exception = $e; - $this->context->transport->success = false; - if (!$this->context->handleExceptions) - $this->context->viewName = 'error-simple'; - (new \Chibi\View())->renderFile($this->context->layoutName); - } catch (\Chibi\MissingViewFileException $e) { $this->context->json = true; $this->context->layoutName = 'layout-json'; (new \Chibi\View())->renderFile($this->context->layoutName); } + catch (SimpleException $e) + { + StatusHelper::failure(rtrim($e->getMessage(), '.') . '.'); + if (!$this->context->handleExceptions) + $this->context->viewName = 'message'; + (new \Chibi\View())->renderFile($this->context->layoutName); + } catch (Exception $e) { - $this->context->transport->errorMessage = rtrim($e->getMessage(), '.') . '.'; - $this->context->transport->errorHtml = TextHelper::parseMarkdown($this->context->transport->errorMessage, true); + StatusHelper::failure(rtrim($e->getMessage(), '.') . '.'); $this->context->transport->exception = $e; $this->context->transport->queries = array_map(function($x) { return preg_replace('/\s+/', ' ', $x); }, queryLogger()->getLogs()); - $this->context->transport->success = false; $this->context->viewName = 'error-exception'; (new \Chibi\View())->renderFile($this->context->layoutName); } diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index 86c135bb..4f5edbc0 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -76,7 +76,7 @@ class AuthController $token = implode('|', [base64_encode($suppliedName), base64_encode($suppliedPassword)]); setcookie('auth', TextHelper::encrypt($token), time() + 365 * 24 * 3600, '/'); } - $this->context->transport->success = true; + StatusHelper::success(); self::redirectAfterLog(); } } diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php index efb20ddb..22991dfa 100644 --- a/src/Controllers/CommentController.php +++ b/src/Controllers/CommentController.php @@ -63,7 +63,7 @@ class CommentController if (InputHelper::get('sender') != 'preview') R::store($comment); $this->context->transport->textPreview = $comment->getText(); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -79,6 +79,6 @@ class CommentController R::preload($comment, ['commenter' => 'user']); PrivilegesHelper::confirmWithException(Privilege::DeleteComment, PrivilegesHelper::getIdentitySubPrivilege($comment->commenter)); R::trash($comment); - $this->context->transport->success = true; + StatusHelper::success(); } } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 583c2522..2889d9a0 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -138,7 +138,7 @@ class PostController $post->sharedTag = $dbTags; R::store($post); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -339,7 +339,7 @@ class PostController } R::store($dbPost); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -437,7 +437,7 @@ class PostController Model_Tag::removeUnused(); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -455,7 +455,7 @@ class PostController { $post->hidden = true; R::store($post); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -471,7 +471,7 @@ class PostController { $post->hidden = false; R::store($post); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -495,7 +495,7 @@ class PostController $post->sharedTag = []; R::store($post); R::trash($post); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -522,7 +522,7 @@ class PostController $post->link('favoritee')->user = $this->context->user; R::store($post); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -551,7 +551,7 @@ class PostController unset ($post->ownFavoritee[$finalKey]); R::store($post); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -580,7 +580,7 @@ class PostController } $p->score = $score; R::store($p); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -596,7 +596,7 @@ class PostController Model_Property::set(Model_Property::FeaturedPostId, $post->id); Model_Property::set(Model_Property::FeaturedPostUserId, $this->context->user->id); Model_Property::set(Model_Property::FeaturedPostDate, time()); - $this->context->transport->success = true; + StatusHelper::success(); } diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 649d9ed9..d35281aa 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -70,7 +70,7 @@ class TagController } R::trash($sourceTag); \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('tag', 'list')); - $this->view->context->success = true; + StatusHelper::success(); } } @@ -101,7 +101,7 @@ class TagController R::store($sourceTag); \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('tag', 'list')); - $this->context->transport->success = true; + StatusHelper::success(); } } diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 641e0383..fd290d8a 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -127,7 +127,7 @@ class UserController { $user->banned = true; R::store($user); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -143,7 +143,7 @@ class UserController { $user->banned = false; R::store($user); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -159,7 +159,7 @@ class UserController { $user->staff_confirmed = true; R::store($user); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -209,7 +209,7 @@ class UserController R::store($user); R::trash($user); \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); - $this->context->transport->success = true; + StatusHelper::success(); } } @@ -247,7 +247,7 @@ class UserController if ($user->id == $this->context->user->id) $this->context->user = $user; AuthController::doReLog(); - $this->context->transport->success = true; + StatusHelper::success('Browsing settings updated!'); } } @@ -312,6 +312,7 @@ class UserController } else { + $user->email_unconfirmed = null; $user->email_confirmed = $suppliedEmail; } } @@ -334,7 +335,10 @@ class UserController if ($confirmMail) self::sendEmailChangeConfirmation($user); - $this->context->transport->success = true; + $message = 'Account settings updated!'; + if ($confirmMail) + $message .= ' You wlil be sent an e-mail address confirmation message soon.'; + StatusHelper::success($message); } } catch (Exception $e) @@ -414,7 +418,7 @@ class UserController if (!$this->context->user->anonymous) R::store($this->context->user); - $this->context->transport->success = true; + StatusHelper::success(); } @@ -485,7 +489,17 @@ class UserController if (!empty($dbUser->email_unconfirmed)) self::sendEmailChangeConfirmation($dbUser); - $this->context->transport->success = true; + $message = 'Congratulations, your account was created.'; + if (!empty($this->context->mailSent)) + { + $message .= ' Please wait for activation e-mail.'; + if ($this->config->registration->staffActivation) + $message .= ' After this, your registration must be confirmed by staff.'; + } + elseif ($this->config->registration->staffActivation) + $message .= ' Your registration must be now confirmed by staff.'; + + StatusHelper::success($message); if (!$this->config->registration->needEmailForRegistering and !$this->config->registration->staffActivation) { @@ -503,6 +517,7 @@ class UserController public function activationAction($token) { $this->context->subTitle = 'account activation'; + $this->context->viewName = 'message'; if (empty($token)) throw new SimpleException('Invalid activation token'); @@ -515,7 +530,7 @@ class UserController throw new SimpleException('This user was already activated'); if ($dbToken->expires !== null and time() > $dbToken->expires) - throw new SimpleException('Activation link expired.'); + throw new SimpleException('Activation link expired'); $dbUser = $dbToken->user; $dbUser->email_confirmed = $dbUser->email_unconfirmed; @@ -523,7 +538,11 @@ class UserController $dbToken->used = true; R::store($dbToken); R::store($dbUser); - $this->context->transport->success = true; + + $message = 'Activation completed successfully.'; + if ($this->config->registration->staffActivation) + $message .= ' However, your account still must be confirmed by staff.'; + StatusHelper::success($message); if (!$this->config->registration->staffActivation) { diff --git a/src/Helpers/StatusHelper.php b/src/Helpers/StatusHelper.php new file mode 100644 index 00000000..774cae96 --- /dev/null +++ b/src/Helpers/StatusHelper.php @@ -0,0 +1,30 @@ +transport->message = $message; + $context->transport->messageHtml = TextHelper::parseMarkdown($message, true); + } + $context->transport->success = $success; + } + + public static function init() + { + $context = \Chibi\Registry::getContext(); + $context->transport->success = null; + } + + public static function success($message = null) + { + self::flag(true, $message); + } + + public static function failure($message = null) + { + self::flag(false, $message); + } +} diff --git a/src/Views/auth-login.phtml b/src/Views/auth-login.phtml index 1518f788..0778a3c9 100644 --- a/src/Views/auth-login.phtml +++ b/src/Views/auth-login.phtml @@ -24,9 +24,7 @@ - context->transport->errorMessage)): ?> -

Error: context->transport->errorMessage ?>

- + renderFile('message') ?> diff --git a/src/Views/error-simple.phtml b/src/Views/error-simple.phtml deleted file mode 100644 index ed1b0f77..00000000 --- a/src/Views/error-simple.phtml +++ /dev/null @@ -1 +0,0 @@ -

Error: context->transport->errorHtml ?>
Go back

diff --git a/src/Views/message.phtml b/src/Views/message.phtml new file mode 100644 index 00000000..7104fea2 --- /dev/null +++ b/src/Views/message.phtml @@ -0,0 +1,5 @@ +context->transport->message)): ?> +

+ context->transport->messageHtml ?> +

+ diff --git a/src/Views/post-upload.phtml b/src/Views/post-upload.phtml index d71cc6f7..b81caba7 100644 --- a/src/Views/post-upload.phtml +++ b/src/Views/post-upload.phtml @@ -1,128 +1,122 @@ -context->transport->success === true): ?> -

Post created!

- + -