public function actionLogin() { $this->view->title = "Вход в систему"; try { $input = \System\Engine::getInput(); if ($input->exists("email")) { $email = $input->getStr("email", null, "Empty email field"); $password = $input->getStr("password", null, "Empty Password field"); UserModel::authorize($email, $password); $this->redirect("/"); } else { return $this->view->htmlPage("user/auth"); } } catch (Exception $e) { return $this->view->htmlPage("user/auth", ['message' => $e->getMessage()]); } }
public function actionSaveComment($post_id) { $post = PostModel::get($post_id); $input = \System\Engine::getInput(); $data = $input->getArray("data"); $data = array_intersect_key($data, array_flip(["name", "message"])); $user = UserModel::isAuthorized(); $data['post_id'] = $post_id; $data['message'] = strip_tags($data['message']); if ($user) { $data['user_id'] = $user->id; } else { $data['name'] = strip_tags($data['name']); } try { $comment = new PostCommentModel(); $comment->setData($data); $comment->save(); $this->redirect("/post/show/{$post->id}#comments"); } catch (Exception $e) { $this->redirect("/post/show/{$post->id}#comments", $e->getMessage()); } }