public function setLayout() { $config = \Chat\Framework\Bootstrap::getConfig(); $view_info = $config['view']; if ($view_info) { $this->layout = new $view_info['layout'](); //$this->setTemplate($view_info['template']); } return $this; //return $this->generate(); }
public function registerAction() { if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password'])) { if (trim($_POST['name']) != '' && trim($_POST['email']) != '' && trim($_POST['password']) != '') { $name = trim($_POST['name']); $email = trim($_POST['email']); $password = trim($_POST['password']); } } try { if (!isset($name) && !isset($email) && !isset($password)) { throw new \Exception('Fill in all the required fields.'); } if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) { throw new \Exception('Your email is invalid.'); } $gravatar = md5(strtolower(trim($password))); $user = new \Chat\App\Core\Model\User(); $user->setName($name); $user->setEmail($email); $user->setGravatar($gravatar); //$homepage = 'lol'; if (isset($_POST['homepage'])) { // $_POST['homepage] $url = $_POST['homepage']; $url = Helper::getRightUrl(trim($url)); // $_POST['homepage] if (!filter_var($url, FILTER_VALIDATE_URL) === false) { $user->setHomepage($url); } } $user->save(); if ($user->getObject()->affected_rows != 1) { throw new \Exception('This email is in use.'); } $session_data = array('name' => $user->getName(), 'gravatar' => Helper::gravatarFromHash($user->getGravatar())); if ($user->getHomepage()) { array_push($session_data, array('homepage' => $user->getHomepage())); } $_SESSION['user'] = $session_data; $this->response = $user->getLoginResponse(); // header('Location: ' . $_SERVER['HTTP_REFERER']); //header('location: index'); $this->_redirect = 'index'; return $this; } catch (\Exception $e) { // $this->response = json_encode(array('error' => $e->getMessage())); \Chat\Framework\Bootstrap::register('error', $e->getMessage()); $this->indexAction(); } }