Пример #1
0
 public function add_group()
 {
     $parameters_array = $this->request->getParameters();
     $group_name = $this->make_seo_friendly_af($parameters_array['group']);
     // totally overkill
     if (!$group_name) {
         Util::set_session('error_msg', 'Page name can\'t be blank bruh');
         Util::redirect_and_exit('/groups');
     }
     $added_page = $this->group_model->add_group($group_name);
     Util::redirect_and_exit('/groups');
 }
Пример #2
0
 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];
 }
Пример #3
0
 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());
 }
Пример #4
0
 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');
     }
 }