Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Events for user login/signup, password reset and comments/reviews for plugins to handle user form submission
givanz175d36331c5a
diff --git a/app/controller/content/comment-trait.php b/app/controller/content/comment-trait.phpindex d167888..302c866 100644--- a/app/controller/content/comment-trait.php+++ b/app/controller/content/comment-trait.php@@ -25,31 +25,41 @@ namespace Vvveb\Controller\Content;use function Vvveb\__;use function Vvveb\model;use function Vvveb\sanitizeHTML;+use Vvveb\System\Event;trait CommentTrait {- private function insertComment($commentType = 'comment', $text = 'comment') {+ private function insertComment($commentType = 'comment', $commentName = 'comment') {$result = false;$post = &$this->request->post;if (isset($post['content'])) {//robots will also fill hidden inputs- $notRobot =+ $notSpam =(isset($post['firstname-empty']) && empty($post['firstname-empty']) &&isset($post['lastname-empty']) && empty($post['lastname-empty']) &&isset($post['subject-empty']) && empty($post['subject-empty']));- if ($notRobot) {- $user = $this->global['user'];+ $user = $this->global['user'];- if ($user) {- $user['author'] = $user['display_name'];- }+ if ($user) {+ $user['author'] = $user['display_name'];+ }++ $post['content'] = sanitizeHTML($post['content']);++ $comment = array_merge($post, $user, [+ 'created_at' => date('Y-m-d H:i:s'),+ 'status' => 0,+ 'notSpam' => $notSpam,+ 'commentType' => $commentType,+ 'commentName' => $commentName,+ ]);- $post['content'] = sanitizeHTML($post['content']);+ list($comment) = Event :: trigger(__CLASS__, __FUNCTION__ , $comment);+ if ($comment && $comment['notSpam']) {//$sql = new \Vvveb\Sql\CommentSQL();$sql = model($commentType);- $comment = array_merge($post, $user, ['created_at' => date('Y-m-d H:i:s'), 'status' => 0]);$result = $sql->add([$commentType => $comment]);if ($result[$commentType]) {@@ -59,10 +69,12 @@ trait CommentTrait {$comments[$comment['slug']][$comment["{$commentType}_id"]] = $comment;$this->session->set($commentType, $comments);- $this->view->success[] = ucfirst($text) . __(' was posted!');+ $this->view->success[] = ucfirst($commentName) . __(' was posted!');} else {$this->view->errors[] = sprintf(__('Error adding %s!'), $text);}+ } else {+ //optional add comment with spam status}}diff --git a/app/controller/user/login-trait.php b/app/controller/user/login-trait.phpindex 1ffc57f..eb9a997 100755--- a/app/controller/user/login-trait.php+++ b/app/controller/user/login-trait.php@@ -23,6 +23,7 @@namespace Vvveb\Controller\User;use function Vvveb\__;+use Vvveb\System\Event;use Vvveb\System\User\User;use Vvveb\System\Validator;@@ -38,20 +39,28 @@ trait LoginTrait {$validator = new Validator(['login']);if ($this->request->post) {- if (($errors['login'] = $validator->validate($this->request->post)) === true) {- if ($userInfo = User::login($this->request->post)) {- $success = __('Login successful!');- $this->session->set('success', ['login' => $success]);- $this->session->close();- $this->view->success['login'] = $success;- $this->view->global['user_id'] = $userInfo['user_id'];- $this->redirect('/user');+ if (($errors = $validator->validate($this->request->post)) === true) {+ $userInfo = $this->request->post;++ list($userInfo) = Event :: trigger(__CLASS__, __FUNCTION__ , $userInfo);++ if ($userInfo) {+ if ($user = User::login($userInfo)) {+ $success = __('Login successful!');+ $this->session->set('success', ['login' => $success]);+ $this->session->close();+ $this->view->success['login'] = $success;+ $this->view->global['user_id'] = $user['user_id'];+ $this->redirect('/user');+ } else {+ //user not found or wrong password+ $this->view->errors['login'] = __('Authentication failed, wrong email or password!');+ }} else {- //user not found or wrong password- $this->view->errors['login'] = __('Authentication failed, wrong email or password!');+ if ($errors !== true) {+ $this->view->errors['login'] = $errors;+ }}- } else {- $this->view->errors = $errors;}}}diff --git a/app/controller/user/reset.php b/app/controller/user/reset.phpindex 3e9115c..5b40982 100644--- a/app/controller/user/reset.php+++ b/app/controller/user/reset.php@@ -25,6 +25,7 @@ namespace Vvveb\Controller\User;use function Vvveb\__;use Vvveb\Controller\Base;use function Vvveb\email;+use Vvveb\System\Event;use Vvveb\System\Functions\Str;use Vvveb\System\Sites;use Vvveb\System\User\User;@@ -68,49 +69,53 @@ class Reset extends Base {if ($email) {$loginData['email'] = $email;- if (($adminData = User::get($loginData)) != false) {- //set reset token and send reset email- $token = Str::random(32);- User::update(['token' => $token], ['email' => $adminData['email']]);-- $agent = $_SERVER['HTTP_USER_AGENT'];-- if (strpos($agent, 'Linux') !== false) {- $os = 'Linux';- } elseif (strpos($agent, 'Win') !== false) {- $os = 'Windows';- } elseif (strpos($agent, 'Mac') !== false) {- $os = 'Mac';- } else {- $os = 'UnKnown';- }-- $site = Sites :: getSiteData();-- $reset_url = url('user/reset/reset', [- 'token' => $token,- 'user' => $adminData['username'],- 'host' => $site['host'] ?? false,- 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http',- ]);-- $data = $adminData + [- 'token' => $token,- 'operating_system' => $os,- 'browser_name' => $_SERVER['HTTP_USER_AGENT'],- 'reset_url' => $reset_url,- ];-- if (email($adminData['email'], __('Password reset'),'user/reset', $data)) {- $success = __('A reset email was sent, please use it to reset your password!');- $this->view->success[] = $success;- $this->session->set('success', ['login' => $success]);- $this->redirect('/user/login');+ list($loginData) = Event :: trigger(__CLASS__, __FUNCTION__ , $loginData);++ if ($loginData) {+ if (($adminData = User::get($loginData)) != false) {+ //set reset token and send reset email+ $token = Str::random(32);+ User::update(['token' => $token], ['email' => $adminData['email']]);++ $agent = $_SERVER['HTTP_USER_AGENT'];++ if (strpos($agent, 'Linux') !== false) {+ $os = 'Linux';+ } elseif (strpos($agent, 'Win') !== false) {+ $os = 'Windows';+ } elseif (strpos($agent, 'Mac') !== false) {+ $os = 'Mac';+ } else {+ $os = 'UnKnown';+ }++ $site = Sites :: getSiteData();++ $reset_url = url('user/reset/reset', [+ 'token' => $token,+ 'user' => $adminData['username'],+ 'host' => $site['host'] ?? false,+ 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http',+ ]);++ $data = $adminData + [+ 'token' => $token,+ 'operating_system' => $os,+ 'browser_name' => $_SERVER['HTTP_USER_AGENT'],+ 'reset_url' => $reset_url,+ ];++ if (email($adminData['email'], __('Password reset'),'user/reset', $data)) {+ $success = __('A reset email was sent, please use it to reset your password!');+ $this->view->success[] = $success;+ $this->session->set('success', ['login' => $success]);+ $this->redirect('/user/login');+ } else {+ $this->view->errors[] = __('Error sending reset email!');+ }} else {- $this->view->errors[] = __('Error sending reset email!');+ $this->view->errors['login'] = __('Email not found!');}- } else {- $this->view->errors['login'] = __('Email not found!');}}}diff --git a/app/controller/user/signup.php b/app/controller/user/signup.phpindex 1491fae..2991ecc 100755--- a/app/controller/user/signup.php+++ b/app/controller/user/signup.php@@ -25,57 +25,68 @@ namespace Vvveb\Controller\User;use function Vvveb\__;use function Vvveb\email;use function Vvveb\siteSettings;+use Vvveb\System\Event;use Vvveb\System\User\User;use Vvveb\System\Validator;class Signup extends \Vvveb\Controller\Base {- function index() {+ function addUser() {//$this->checkAlreadyLoggedIn();-$validator = new Validator(['signup']);if ($this->request->post &&- ($this->view->errors['signup'] = $validator->validate($this->request->post)) === true) {+ ($this->view->errors['login'] = $validator->validate($this->request->post)) === true) {//allow only fields that are in the validator list and remove the rest$userInfo = $validator->filter($this->request->post);$userInfo['display_name'] = $userInfo['first_name'] . ' ' . $userInfo['last_name'];$userInfo['username'] = $userInfo['first_name'] . $userInfo['last_name'];- $result = User::add($userInfo);- $this->view->errors['login'] = [];+ list($userInfo) = Event :: trigger(__CLASS__, __FUNCTION__ , $userInfo);++ if ($userInfo) {+ $result = User::add($userInfo);- if ($result) {- if (is_array($result)) {- $message = __('User created!');- $this->session->set('success', ['login' => $message]);- $this->view->success['login'][] = $message;- $user_id = $result['user'];- $this->request->request['user_id'] = $user_id;+ $this->view->errors['login'] = [];- $site = siteSettings();+ if ($result) {+ if (is_array($result)) {+ $message = __('User created!');+ $this->session->set('success', ['login' => $message]);+ $this->view->success['login'][] = $message;+ $user_id = $result['user'];+ $this->request->request['user_id'] = $user_id;- try {- $error = __('Error sending account creation mail!');+ $site = siteSettings();- if (! email([$userInfo['email'], $site['admin-email']], __('Your account has been created!'), 'user/signup', $userInfo)) {+ try {+ $error = __('Error sending account creation mail!');++ if (! email([$userInfo['email'], $site['admin-email']], __('Your account has been created!'), 'user/signup', $userInfo)) {+ $this->session->set('errors', ['login' => $error]);+ $this->view->errors[] = $error;+ }+ } catch (\Exception $e) {+ if (DEBUG) {+ $error .= "\n" . $e->getMessage();+ }$this->session->set('errors', ['login' => $error]);- $this->view->errors[] = $error;- }- } catch (\Exception $e) {- if (DEBUG) {- $error .= "\n" . $e->getMessage();+ $this->view->errors['login'] = $error;}- $this->session->set('errors', ['login' => $error]);- $this->view->errors['login'] = $error;- }- return $this->redirect('user/index');+ return $this->redirect('user/index');+ } else {+ $this->view->errors['login'] = __('This email is already in use. Please use another one.');+ }} else {- $this->view->errors['login'] = __('This email is already in use. Please use another one.');+ $this->view->errors['login'] = __('Error creating user!');}- } else {- $this->view->errors['login'] = __('Error creating user!');}}}++ function index() {+ if ($this->request->post) {+ $this->addUser();+ }+ }}diff --git a/app/template/editor.tpl b/app/template/editor.tplindex 3ad448c..c0b252b 100755--- a/app/template/editor.tpl+++ b/app/template/editor.tpl@@ -1,14 +1,14 @@//set editing flaghead|append = <?php-$is_editor = $vvveb_is_page_edit = Vvveb\isEditor();+$vvveb_is_page_edit = $vvveb_is_page_edit = Vvveb\isEditor();$is_admin = \Vvveb\isAdmin();-if ($is_admin && !$is_editor) {+if ($is_admin && !$vvveb_is_page_edit) {echo '<link href="' . Vvveb\publicUrlPath() . 'admin/default/css/admin-bar.css" rel="stylesheet">';}?>body|prepend = <?php-if (isset($is_admin) && $is_admin && !$is_editor) {+if (isset($is_admin) && $is_admin && !$vvveb_is_page_edit) {include_once(DIR_ROOT . '/admin/admin-bar.php');}?>