예제 #1
0
 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();
 }
예제 #2
0
 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');
     }
 }
예제 #3
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];
 }
예제 #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');
     }
 }