Beispiel #1
0
 public function onConstruct()
 {
     $userid = \User::check_token();
     $user = \User::findFirst([['userid' => $userid]]);
     if ($user) {
         $this->user = $user->attrs();
     }
 }
Beispiel #2
0
 protected function registerEvents()
 {
     $this->before(function () {
         // restangular post data
         if (!$_POST) {
             if (stripos($_SERVER["CONTENT_TYPE"], "application/json") === 0) {
                 $_POST = json_decode(file_get_contents("php://input"), true);
             }
         }
         // page visit access
         $uri = $_GET['_url'];
         // if(!$this->request->isAjax() &&
         // 	!in_array($uri, ['/', '/user/active', '/movie/upload']))
         // {
         // 	echo 'params error';
         // 	return false;
         // }
         // checklogin
         if (in_array($uri, $this->should_login)) {
             $userid = \User::check_token();
             if (!$userid) {
                 echo '[]';
                 return false;
             }
         }
     });
     $this->finish(function () {
         $output = $this->getReturnedValue();
         if (is_string($output)) {
             $output = ['error' => $output];
         }
         if (is_array($output)) {
             echo json($output);
         }
     });
 }