public function show_profile() { $error_msg = Util::get_session('error_msg'); if (!empty($error_msg)) { Util::un_set_session('error_msg'); } $data = array('error' => isset($error_msg) ? $error_msg : null, 'user_id' => isset($this->user_id) ? $this->user_id : null, 'email' => isset($this->email) ? $this->email : null); $html = $this->renderer->render('partials/login', $data); $this->response->setContent($html); echo $this->response->getContent(); }
public function display_group($response_params) { $error_msg = Util::get_session('error_msg'); $group = $response_params['group']; $images = $this->image_model->get_images($group); $data = ['images' => !empty($images) ? $images : null, 'group' => $group, 'error' => isset($error_msg) ? $error_msg : null]; $data = array_merge($data, $this->data); // merge with parent data $html = $this->renderer->render('partials/group', $data); $this->response->setContent($html); echo $this->response->getContent(); if ($error_msg) { Util::un_set_session('error_msg'); } }
public function __construct(Request $request, Response $response, FrontendRenderer $renderer) { $this->request = $request; $this->response = $response; $this->renderer = $renderer; $this->user_id = Util::get_session('user_id'); $this->email = Util::get_session('email'); $this->group_model = new GroupModel(); if (empty($this->user_id)) { Util::set_session('error_msg', 'sorry'); Util::redirect_and_exit('/login'); return; } $this->groups = $this->group_model->get_groups(); $this->data = ['user_id' => isset($this->user_id) ? $this->user_id : null, 'email' => isset($this->email) ? $this->email : null, 'groups' => isset($this->groups) ? $this->groups : null]; }
public function add_image() { $file_array = $this->request->getFiles(); $parameters_array = $this->request->getParameters(); // if theres an image set if ($file_array['image-file']['size']) { if (!is_uploaded_file($file_array['image-file']['tmp_name']) || !getimagesize($file_array['image-file']['tmp_name']) || $file_array['image-file']['error']) { Util::set_session('error_msg', 'there was an error with the image'); } } if (!$parameters_array['title']) { Util::set_session('error_msg', 'You didn\'t give a title and image!'); } else { $img = $this->image_model->add_image(array_merge($file_array, $parameters_array)); } Util::redirect_and_exit($this->request->getReferer()); }
<?php namespace Aframe; use Aframe\Utils\Util; require ROOT . '/vendor/autoload.php'; if (strpos(Util::getFullUrl(), '.dev')) { ini_set('display_errors', 1); error_reporting(E_ALL); define('ENV', 'dev'); } else { define('ENV', 'prod'); } require ROOT . '/config/config.php'; $injector = (include 'dependencies.php'); $request = $injector->make('Http\\HttpRequest'); $response = $injector->make('Http\\HttpResponse'); foreach ($response->getHeaders() as $header) { header($header, false); } /** * Register the error handler */ $whoops = new \Whoops\Run(); if (defined('ENV') && ENV === 'dev') { $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); } else { $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); } $whoops->register(); $routeDefinitionCallback = function (\FastRoute\RouteCollector $r) {
public function signup() { $params = $this->request->getParameters(); if (!$params['email'] || !$params['password'] || !$params['form_token'] || !$params['code']) { $error_msg = 'Please enter a valid username, password, and the code!'; } if ($params['form_token'] != Util::get_session('form_token')) { $error_msg = 'Invalid form submission'; } if (strlen($params['email']) > 30 || strlen($params['email']) < 4) { $error_msg = 'Incorrect Length for Username'; } if (strlen($params['password']) > 30 || strlen($params['password']) < 4) { $error_msg = 'Incorrect Length for Password'; } if (!filter_var($params['email'], FILTER_VALIDATE_EMAIL)) { $error_msg = "Username must be an email"; } if ($params['code'] !== CODE) { $error_msg = "Incorrect Code!"; } // not the best, lets validate password eventually // else if (ctype_alnum($params['password']) != true) if (!isset($error_msg)) { $email = filter_var($params['email'], FILTER_SANITIZE_STRING); $password = filter_var($params['password'], FILTER_SANITIZE_STRING); $password = sha1($password); $user = new Usermodel(DB_HOST, DB_USER, DB_PASS, DB); $results = $user->check_used_email($email); if (!$results) { $error_msg = 'There was a database error'; } else { if ($results->num_rows) { $error_msg = 'That email is alrady taken, try another one'; } else { $new_user = $user->make_user($email, $password); if (!$new_user) { $error_msg = 'There was an error signging up'; } } } } if (isset($error_msg)) { Util::set_session('error_msg', $error_msg); Util::redirect_and_exit($this->request->getUri()); } else { Util::redirect_and_exit('/login'); } }