示例#1
0
 /**
  * Thư mục 'storage' của user
  * Khi có lỗi, $ignore_error =
  * - true: return [eror code, message]
  * - false: dừng app bằng 'abort'
  *
  * @param string $path
  * @param bool $ignore_error
  * @param int|null $id
  *
  * @return string|array
  */
 function user_storage_path($path = '', $ignore_error = false, $id = null)
 {
     if ($username = user('username', $id)) {
         $path = storage_path("data/{$username}" . ($path ? "/{$path}" : ''));
         return check_path($path, $ignore_error, $path);
     } else {
         return response_error(3, 'Not call user_storage_path() for Guest', $ignore_error);
     }
 }
示例#2
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     //Credit to Nyan Lynn Htut :D
     //$status = $e->getStatusCode();
     $message = $e->getMessage() ?: null;
     if ($e instanceof NotFoundHttpException) {
         return response_missing();
     }
     if ($e instanceof MethodNotAllowedHttpException) {
         return response_error('Invalid Method call.');
     }
     return response_error(!is_null($message) ? $message : 'Error occured!');
 }
示例#3
0
文件: core.php 项目: Osuka42g/papi
function run()
{
    $func = $_GET['pApifw'];
    if (isset($_GET['pApifwnext'])) {
        $next = $_GET['pApifwnext'];
    } else {
        $next = false;
    }
    if (is_callable($func)) {
        if ($next) {
            call_user_func($func, $next);
        } else {
            call_user_func($func);
        }
    } else {
        response_error();
        return false;
    }
    return 0;
}
 /**
  * Generate the token for given api key.
  *
  * @param  string $key
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function generate($key)
 {
     $app = Application::where('key', '=', $key)->first();
     if (is_null($app) || $app->disable) {
         $msg = is_null($app) ? 'Invalid app key' : 'Application is disable';
         return response_unauthorized($msg);
     }
     $tokenValue = $this->getUUID5Token($app);
     if ($tokenValue) {
         $token = new Token();
         $token->app_id = $app->id;
         // Application ID
         $token->app_key = $app->key;
         // Application Key
         $token->user_id = $app->user_id;
         // Application owner id
         $token->token = $tokenValue;
         // Token for unique user.
         if ($token->save()) {
             return response_ok($token);
         }
     }
     return response_error('Error occured to generate token. Please try again');
 }
 private function getAnalyticData($url, $query = [])
 {
     $client = new Client(['base_uri' => $this->base_url]);
     try {
         $response = $client->get($url, ['headers' => ['X-API-KEY' => $this->api_key, 'X-API-SECRET' => $this->api_secret], 'query' => $query]);
     } catch (\Exception $e) {
         return response_error("Internal Server Error.");
     }
     switch ($response->getStatusCode()) {
         case 500:
             return response_error("Internal Server Error.");
             break;
         case 401:
             response_unauthorized();
             break;
         case 404:
             return response_missing();
             break;
         case 200:
             return response_ok(json_decode($response->getBody()->getContents()));
             break;
     }
     return response_error("Internal Server Error.");
 }
示例#6
0
文件: vh.js.php 项目: madbob/VoiceHub
        curl_setopt($ch, CURLOPT_USERPWD, sprintf('%s:%s', $conf['username'], $conf['password']));
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_USERAGENT, 'VoiceHub');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($issue));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/vnd.github.v3.json+json', 'Content-Type: application/json'));
        $response = curl_exec($ch);
        $response = json_decode($response);
        if (isset($response->html_url)) {
            $r = (object) ['url' => $response->html_url];
            echo json_encode($r);
        } else {
            response_error($langs[$lang]['error_save']);
        }
        break;
    case 'GET':
        ?>

                +function ($) {
                        var VoiceHub = function() {
                                this.project = '<?php 
        if (isset($conf['fixed_project']) && !empty($conf['fixed_project'])) {
            echo $conf['fixed_project'];
        } else {
            if (isset($_GET['project']) && !empty($_GET['project'])) {
                echo $_GET['project'];
            } else {
                echo $conf['default_project'];
示例#7
0
/**
 * Alias of response_error
 * @param $code
 * @param $message
 * @return array
 */
function error($code, $message)
{
    return response_error($code, $message);
}
示例#8
0
 /**
  * Generate User Token
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  **/
 public function generateToken(Request $request)
 {
     if ($request->has('api_key')) {
         $apiKey = $request->input('api_key');
         $authUrl = config('app.auth');
         $client = new Client(['base_url' => $authUrl['base_url']]);
         $headers = ['X-API-KEY' => env('AUTH_APP_KEY'), 'X-API-SECRET' => env('AUTH_APP_SECRET')];
         try {
             $tokenResponse = $client->get($authUrl['token_uri'] . '/' . $apiKey, ['headers' => $headers]);
         } catch (ClientException $e) {
             $tokenResponse = $e->getResponse();
         }
         switch ($tokenResponse->getStatusCode()) {
             case 200:
                 $responseData = $tokenResponse->json();
                 return response_ok(['_meta' => ['status' => 'ok', 'count' => 1, 'api_version' => 1], 'data' => ['token' => $responseData['token']]]);
                 break;
             case 500:
                 return response_error("Something wrong with token generate process");
                 break;
             default:
                 return response()->json($tokenResponse->json(), $tokenResponse->getStatusCode());
                 break;
         }
     }
     return response_missing("You must pass your 'api_key' to generate user token.");
 }
示例#9
0
function m_set_score()
{
    global $xoopsSecurity;
    $id = rmc_server_var($_POST, 'id', 0);
    $token = rmc_server_var($_POST, 'token', 0);
    $local = rmc_server_var($_POST, 'local', 0);
    $visitor = rmc_server_var($_POST, 'visitor', 0);
    $other = rmc_server_var($_POST, 'other', 0);
    $comments = rmc_server_var($_POST, 'comments', 0);
    $win = rmc_server_var($_POST, 'win', 0);
    $champ = rmc_server_var($_POST, 'win', 0);
    if ($id <= 0) {
        response_error(__('No role item has been specified!', 'match'));
    }
    if (!$xoopsSecurity->check(true, $token)) {
        response_error(__('Session token expired!', 'match'));
    }
    $item = new MCHRoleItem($id);
    if ($item->isNew()) {
        response_error(__('Specified role item does not exists', 'match'));
    }
    $score = new MCHScoreItem();
    $score->byRole($item->id());
    $score->setVar('item', $id);
    $score->setVar('local', $local);
    $score->setVar('visitor', $visitor);
    $score->setVar('other', $other);
    $score->setVar('comments', $comments);
    $score->setVar('win', $local > $visitor ? $item->getVar('local') : ($visitor > $local ? $item->getVar('visitor') : $win));
    $score->setVAr('champ', $item->getVar('champ'));
    if ($score->save()) {
        $ret = array('done' => 1);
        echo json_encode($ret);
        die;
    } else {
        response_error($score->errors());
    }
}
示例#10
0
 /**
  * Adds a screenshot to a project via a file upload.  Requires that the file be uploaded as 'upload'
  * @param $project
  */
 private function add_screen_upload($project)
 {
     $config = array('upload_path' => $this->config->item('screen_upload_dir'), 'allowed_types' => $this->config->item('screen_upload_types'), 'max_size' => $this->config->item('max_screen_upload_size'), 'encrypt_name' => true);
     /* Handle the file upload */
     $this->load->library('upload', $config);
     if ($this->upload->do_upload('file')) {
         $data = $this->upload->data();
         /* Upload to s3 */
         $client = S3Client::factory(array('credentials' => array('key' => $this->config->item('s3_access_key_id'), 'secret' => $this->config->item('s3_secret')), 'region' => $this->config->item('s3_region'), 'version' => $this->config->item('s3_version')));
         $object = array('Bucket' => $this->config->item('s3_bucket'), 'Key' => $data['file_name'], 'SourceFile' => $data['full_path'], 'ACL' => 'public-read');
         $result = $client->putObject($object);
         if ($result['ObjectURL']) {
             $insert = array('creator_id' => get_user_id(), 'project_id' => $project->id, 'ordering' => $this->Screen->get_max_ordering_for_project($project->id) + 1, 'url' => $data['file_name'], 'file_type' => $data['file_type'], 'file_size' => $data['file_size'], 'image_height' => $data['image_height'], 'image_width' => $data['image_width']);
             $screen = $this->Screen->load($this->Screen->add($insert));
             unlink($data['full_path']);
             return $screen;
         } else {
             log_message('info', '[File Add] putObject Result: ' . print_r($result, TRUE));
             return json_error('File Upload to S3 Failed: ', $result);
         }
     } else {
         response_error($this->upload->display_errors());
         exit;
     }
 }