Example #1
0
 protected function aclAccessFail($zone, $action)
 {
     if ($zone === 'not login') {
         return $this->_redirect('pages/restricted');
     }
     Session::error('You gotsta be logged for this shit right here');
     $this->_redirect('pages/login');
 }
Example #2
0
 public function loginAction()
 {
     $form = new LoginForm($this);
     if ($this->POST) {
         if ($form->validate($_POST)) {
             try {
                 $user = User::withCredentials($form->output['default']);
                 $this->user->login($user);
                 return $this->_redirect('');
             } catch (NotEnoughFoundException $ex) {
             }
         }
         $form->input['pasword'] = '';
         Session::error('Invalid login');
     }
     return get_defined_vars();
 }
 public function add_comment($post)
 {
     $post = $this->getPost($post);
     $anonymous = $this->user->isLoggedIn() ? '' : '_anonymous';
     $validator = models\Comment::validator('add' . $anonymous);
     //echo '<pre>';
     //print_r($validator); exit;
     if (!empty($_POST)) {
         if ($validator->validate($_POST, $context)) {
             $insert = $validator->output;
             if (!$this->user->isLoggedIn() && isset($context['user'])) {
                 $this->user->login($context['user']);
             }
             //print_r($insert); print_r($context); exit;
             $insert['post_id'] = $post->post_id;
             $insert['created_on'] = time();
             $insert['created_by_ip'] = $_SERVER['REMOTE_ADDR'];
             //print_r($insert); exit;
             try {
                 $cid = models\Comment::insert($insert);
                 //var_dump($cid); exit;
                 $comment = models\Comment::get($cid);
                 //print_r($comment); exit;
                 Session::success('Comment created');
                 $this->_redirect($comment->url());
             } catch (\Exception $ex) {
                 Session::error('Didn\'t save... Try again!?');
             }
         } else {
             Session::error('See input errors below:');
         }
     }
     $messages = Session::messages();
     return $this->tpl->display('blog/comment_form', get_defined_vars());
 }
 public function login($uid = null)
 {
     if (null !== $uid) {
         $this->user->login(models\User::get($uid));
     }
     if ($this->user->isLoggedIn()) {
         $this->_redirect('/blog');
     }
     if ($this->POST) {
         $post = options($_POST);
         $get = options($_GET);
         try {
             // get user object
             $user = models\User::withCredentials(array('username' => (string) $post->username, 'password' => (string) $post->password));
             // log user in(to SessionUser)
             $this->user->login($user);
             // debug direct logged in status
             Session::message('<pre>' . var_export($this->user->isLoggedIn(), 1) . '</pre>');
             // message OK
             Session::success('Alright, alright, alright, you\'re logged in...');
             // back to blog
             return $this->_redirect($post->get('goto', $get->get('goto', 'blog')));
         } catch (\Exception $ex) {
         }
         // message FAIL
         Session::error('Sorry, buddy, that\'s not your username!');
     }
     $messages = Session::messages();
     return get_defined_vars();
 }