Example #1
0
 /**
  * This method will be called after we route to the destinated method
  * 
  * @access  public
  * @return 	void
  */
 public function before()
 {
     $this->language = Factory::get_language();
     $this->user = Auth::make('user')->get();
     Event::trigger('controller_before');
     if (Request::is_hmvc()) {
         $this->set_content_type = false;
     }
     Restserver::auth();
     return parent::before();
 }
Example #2
0
 /**
  * Unauthorized an action, this should be called from within a controller (included in all Hybrid\Controller classes).
  *
  * @access  public
  * @param   string   $resource    A string of resource name
  * @param   bool     $rest        Boolean value to define weither it's a restful call or a normal http call
  * @return  Closure
  * @throws  AclException
  */
 public function unauthorized($resource, $rest = false)
 {
     Lang::load('autho', 'autho');
     $action = array_key_exists($resource, $this->actions) ? $this->actions[$resource] : null;
     $set_content_type = true;
     $response = Response::forge(Lang::get('autho.unauthorized', array(), 'Unauthorized'), 401);
     // run the callback action
     if ($action instanceof Closure and true !== $rest) {
         $callback = $action();
         if ($callback instanceof Response) {
             $response = $callback;
         }
     } else {
         if ($rest === true) {
             if (true === \Request::is_hmvc()) {
                 $set_content_type = false;
             }
         } else {
             throw new HttpNotFoundException();
         }
     }
     Event::shutdown();
     $response->send($set_content_type);
 }