コード例 #1
0
 public function githubLogin()
 {
     $access_token = Input::get('access_token');
     $ch = curl_init('https://api.github.com/user');
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: token {$access_token}"));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
     curl_setopt($ch, CURLOPT_USERAGENT, 'SWAMP');
     $response = curl_exec($ch);
     $user = json_decode($response);
     $account = LinkedAccount::where('user_external_id', '=', $user->id)->first();
     if ($account) {
         Session::set('github_access_token', $access_token);
         $user = User::getIndex($account->user_uid);
         if ($user) {
             if ($user->isEnabled()) {
                 $res = Response::json(array('user_uid' => $user->user_uid));
                 Session::set('timestamp', time());
                 Session::set('user_uid', $user->user_uid);
                 return $res;
             } else {
                 return Response::make('User has not been approved.', 401);
             }
         } else {
             return Response::make('Incorrect username or password.', 401);
         }
     } else {
         return Response::make('Account not found.', 401);
     }
 }
コード例 #2
0
 /**
  * Index action.
  *
  * @return mixed
  */
 public function getIndex($type = null)
 {
     $container = Input::get('c');
     $files = Input::get('files', '');
     if (empty($type) || !in_array($type, array('style', 'script'))) {
         App::abort(404);
     }
     if (empty($container)) {
         App::abort(404);
     }
     $files = json_decode(base64_decode($files), true);
     if (empty($files) || !is_array($files)) {
         App::abort(404);
     }
     foreach ($files as $file) {
         Casset::container($container)->add(array_get($file, 'source'), array(), array_get($file, 'dependencies', array()));
     }
     $response = Response::make(Casset::container($container)->content($type));
     if ('style' == $type) {
         $response->headers->set('Content-Type', 'text/css');
     } else {
         $response->headers->set('Content-Type', 'application/json');
     }
     return $response;
 }
コード例 #3
0
 /**
  * Add route filters.
  *
  * @return void
  */
 protected function bootFilters()
 {
     if (config('api.cors_enabled', true)) {
         $this->app['router']->before(function ($request) {
             if (Request::header('Origin') && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
                 $response = Response::make(null, 204);
                 Cors::attachHeaders($response);
                 Cors::attachOriginHeader($response, Request::header('Origin'));
                 return $response;
             }
         });
         $this->app['router']->after(function ($request, $response) {
             if (Request::header('Origin')) {
                 Cors::attachHeaders($response);
                 Cors::attachOriginHeader($response, Request::header('Origin'));
             }
         });
     }
     $this->app['router']->filter('protect', function ($route, $request) {
         Api::protect();
     });
     $this->app['router']->filter('checkscope', function ($route, $request, $scope = '') {
         // B/c Laravel uses : as a special character already.
         $scope = str_replace('.', ':', $scope);
         Api::checkScope($scope);
     });
 }
コード例 #4
0
 public function index(Request $request)
 {
     $parameters = $request->route()->parameters();
     $parser = new Parser($parameters);
     $generator = new Generator($request->path());
     if (!isset($parameters['version']) && !isset($parameters['resource']) && !isset($parameters['action'])) {
         $segments = ['index'];
     } else {
         $segments = $parameters;
     }
     $file = base_path('resources/' . config('apidocu.base') . '/' . implode('/', $segments) . '.md');
     if (file_exists($file)) {
         $content = file_get_contents($file);
         $status = 200;
     } else {
         $status = 404;
         switch (config('apidocu.404.type')) {
             case 'text':
                 $content = config('apidocu.404.value');
                 break;
             case 'view':
                 $content = view(config('apidocu.404.value'));
                 break;
             default:
                 $content = '**404 - page not found**';
                 break;
         }
     }
     $content = $parser->parse($content);
     return Response::make(view('apidocu::index')->with(['navigation' => $generator->navigation(), 'breadcrumb' => $generator->breadcrumb(), 'content' => $content]), $status);
 }
コード例 #5
0
 public function getActivity(Request $request)
 {
     $me = GitHub::me()->show();
     $lastEventId = $request->session()->get('last_notification_id', false);
     $activity = [];
     $interval = 60;
     if ($lastEventId) {
         list($interval, $activity) = $this->findNewActivity($me['login'], $lastEventId);
         if ($activity) {
             $request->session()->set('last_notification_id', $activity[0]['id']);
             // Mark as read
             try {
                 GitHub::notification()->markRead();
             } catch (\Exception $e) {
                 // Github returns empty string for this endpoint but the API library tries to parse it as json
             }
             foreach ($activity as &$notice) {
                 $notice['html_url'] = $this->getRelatedHtmlUrl($notice['subject']);
             }
         }
     }
     $html = view('notifications.live', ['me' => $me, 'activity' => $activity]);
     $data = ['activity' => $html->render(), 'interval' => (int) $interval * 1000, 'count' => count($activity)];
     $response = \Illuminate\Support\Facades\Response::make(json_encode($data), 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
コード例 #6
0
 public function postCreate()
 {
     // create a single model
     //
     $projectInvitation = new ProjectInvitation(array('project_uid' => Input::get('project_uid'), 'invitation_key' => GUID::create(), 'inviter_uid' => Input::get('inviter_uid'), 'invitee_name' => Input::get('invitee_name'), 'email' => Input::get('email')));
     $user = User::getByEmail(Input::get('email'));
     if ($user) {
         if (ProjectMembership::where('user_uid', '=', $user->user_uid)->where('project_uid', '=', Input::get('project_uid'))->where('delete_date', '=', null)->first()) {
             return Response::json(array('error' => array('message' => Input::get('invitee_name') . ' is already a member')), 409);
         }
     }
     $invite = ProjectInvitation::where('project_uid', '=', Input::get('project_uid'))->where('email', '=', Input::get('email'))->where('accept_date', '=', null)->where('decline_date', '=', null)->first();
     if ($invite) {
         return Response::json(array('error' => array('message' => Input::get('invitee_name') . ' already has a pending invitation')), 409);
     }
     // Model valid?
     //
     if ($projectInvitation->isValid()) {
         $projectInvitation->save();
         $projectInvitation->send(Input::get('confirm_route'), Input::get('register_route'));
         return $projectInvitation;
     } else {
         $errors = $projectInvitation->errors();
         return Response::make($errors->toJson(), 409);
     }
 }
コード例 #7
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->filter('auth', function () {
         if (Auth::guest()) {
             if (Request::ajax()) {
                 return Response::make('Unauthorized', 401);
             } else {
                 return Redirect::guest('/');
             }
         }
     });
     $router->filter('auth.basic', function () {
         return Auth::basic();
     });
     $router->filter('guest', function () {
         if (Auth::check()) {
             return Redirect::to('/');
         }
     });
     $router->filter('admin', function () {
         if (Auth::check()) {
             if (Auth::user()->email != "*****@*****.**") {
                 return Redirect::to('/');
             }
         } else {
             return Redirect::to('/');
         }
     });
     parent::boot($router);
 }
コード例 #8
0
 protected function sendLockoutResponse(Request $request)
 {
     if ($request->ajax()) {
         return Response::make("Too Many Requests", 429);
     }
     return $this->traitSendLockoutResponse($request);
 }
コード例 #9
0
ファイル: ApiController.php プロジェクト: kife-design/knoters
 protected function respondWithArray(array $array, array $headers = [])
 {
     $mimeTypeRaw = Input::server('HTTP_ACCEPT', '*/*');
     // If its empty or has */* then default to JSON
     if ($mimeTypeRaw === '*/*') {
         $mimeType = 'application/json';
     } else {
         // You'll probably want to do something intelligent with charset if provided
         // This chapter just assumes UTF8 everything everywhere
         $mimeParts = (array) explode(',', $mimeTypeRaw);
         $mimeType = strtolower($mimeParts[0]);
     }
     switch ($mimeType) {
         case 'application/json':
             $contentType = 'application/json';
             $content = json_encode($array);
             break;
         case 'application/x-yaml':
             $contentType = 'application/x-yaml';
             $dumper = new YamlDumper();
             $content = $dumper->dump($array, 2);
             break;
         default:
             $contentType = 'application/json';
             $content = json_encode(['error' => ['code' => static::CODE_INVALID_MIME_TYPE, 'http_code' => 415, 'message' => sprintf('Content of type %s is not supported.', $mimeType)]]);
     }
     $response = Response::make($content, $this->statusCode, $headers);
     $response->header('Content-Type', $contentType);
     return $response;
 }
コード例 #10
0
 public function putVerify($verificationKey)
 {
     $emailVerification = EmailVerification::where('verification_key', '=', $verificationKey)->first();
     $emailVerification->verify_date = new DateTime();
     $userAccount = UserAccount::where('user_uid', '=', $emailVerification->user_uid)->first();
     $user = User::getIndex($emailVerification->user_uid);
     $username = $user->username;
     $user->email = $emailVerification->email;
     unset($user->owner);
     unset($user->username);
     $errors = array();
     if ($userAccount->email_verified_flag != 1 || $user->isValid($errors)) {
         $user->username = $username;
         $user->modify();
     } else {
         $message = "This request could not be processed due to the following:<br/><br/>";
         $message .= implode('<br/>', $errors);
         $message .= "<br/><br/>If you believe this to be in error or a security issue, please contact the SWAMP immediately.";
         return Response::make($message, 500);
     }
     // automatically send welcome email iff email has never been verified
     //
     if ($userAccount->email_verified_flag != 1) {
         Mail::send('emails.welcome', array('user' => $user, 'logo' => Config::get('app.cors_url') . '/images/logos/swamp-logo-small.png', 'manual' => Config::get('app.cors_url') . '/documentation/SWAMP-UserManual.pdf'), function ($message) use($user) {
             $message->to($user->email, $user->getFullName());
             $message->subject('Welcome to the Software Assurance Marketplace');
         });
     }
     $userAccount->email_verified_flag = 1;
     $userAccount->save();
     $emailVerification->save();
     return Response::make('This email address has been verified.', 200);
 }
コード例 #11
0
 function checkBuildSystem()
 {
     switch ($this->build_system) {
         case 'none':
             return Response::make("Python package ok for no build.", 200);
             break;
         case 'distutils':
             // create archive from package
             //
             $archive = new Archive($this->getPackagePath());
             $buildPath = Archive::concatPaths($this->source_path, $this->build_dir);
             $buildFile = $this->build_file;
             // search archive for build file in build path
             //
             if ($buildFile != NULL) {
                 if ($archive->contains($buildPath, $buildFile)) {
                     return Response::make("Python package build system ok for build with distutils.", 200);
                 } else {
                     return Response::make("Could not find a build file called '" . $buildFile . "' within the '" . $buildPath . "' directory. You may need to set your build path or the path to your build file.", 404);
                 }
             }
             break;
         case 'other':
             return Response::make("Python package ok for no build.", 200);
             break;
     }
 }
コード例 #12
0
 public function markAcceptance($policyCode, $userUid)
 {
     // get inputs
     //
     $policy = Policy::where('policy_code', '=', $policyCode)->first();
     $user = User::getIndex($userUid);
     $acceptFlag = Input::has('accept_flag');
     // check inputs
     //
     if (!$user || !$policy || !$acceptFlag) {
         return Response::make('Invalid input.', 404);
     }
     // check privileges
     //
     if (!$user->isAdmin() && $user->user_uid != Session::get('user_uid')) {
         return Response::make('Insufficient privileges to mark policy acceptance.', 401);
     }
     // get or create new user policy
     //
     $userPolicy = UserPolicy::where('user_uid', '=', $userUid)->where('policy_code', '=', $policyCode)->first();
     if (!$userPolicy) {
         $userPolicy = new UserPolicy(array('user_policy_uid' => GUID::create(), 'user_uid' => $userUid, 'policy_code' => $policyCode));
     }
     $userPolicy->accept_flag = $acceptFlag;
     $userPolicy->save();
     return $userPolicy;
 }
コード例 #13
0
 /**
  * Return the current response instance.
  *
  * @return Response
  */
 protected function response()
 {
     if (!isset($this->response)) {
         $this->response = Response::make();
     }
     return $this->response;
 }
コード例 #14
0
 /**
  * Return a new "deleted" response object
  *
  * @param  array|object $object
  * @return Response
  */
 public function deleted($object = null)
 {
     if ($object != null) {
         return Response::json($object, 200);
     } else {
         return Response::make(null, 204);
     }
 }
コード例 #15
0
 /**
  * Returns the view for the XHR response with the product information for the search suggestion.
  *
  * @return Response Response object containing the generated output
  */
 public function suggestAction()
 {
     $params = app('Aimeos\\Shop\\Base\\Page')->getSections('catalog-suggest');
     $contents = View::make('shop::catalog.suggest', $params);
     $response = Response::make($contents, 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
コード例 #16
0
 protected function registerDevelopRoute(ScriptFinder $finder)
 {
     foreach ($finder->getScriptUrlTable() as $url => $path) {
         Route::get("{$url}", function () use($path) {
             return Response::make(App::make('script-auto-compiler-l4')->compile($path), 200, ['Content-Type' => 'text/javascript']);
         });
     }
 }
コード例 #17
0
ファイル: AppServiceProvider.php プロジェクト: tajrish/api
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $this->app->make('Dingo\\Api\\Transformer\\Factory')->setAdapter(function ($app) {
         return new Fractal(new Manager(), 'include', ',');
     });
     $this->app->make('Dingo\\Api\\Exception\\Handler')->register(function (ModelNotFoundException $exception) {
         return Response::make(['message' => trans('messages.not_found'), 'status_code' => 404], 404);
     });
 }
コード例 #18
0
ファイル: SwaggerController.php プロジェクト: latrell/swagger
 public function getDocs($page = 'api-docs.json')
 {
     $path = head((array) config('latrell-swagger.output')) . DIRECTORY_SEPARATOR . $page;
     if (!file_exists($path)) {
         App::abort(404);
     }
     $content = file_get_contents($path);
     return Response::make($content)->header('Content-Type', 'application/json');
 }
コード例 #19
0
 protected function showImageFile($file)
 {
     $headers['Content-Type'] = Storage::disk('powerimage')->mimeType($file);
     $headers['Content-Length'] = Storage::disk('powerimage')->size($file);
     $headers['Cache-Control'] = 'max-age=7776000, public';
     $headers['Expires'] = date_create('+90 days')->format('D, d M Y H:i:s') . ' GMT';
     $headers['PowerImage'] = 'Compressed';
     return Response::make(Storage::disk('powerimage')->get($file), 200, $headers);
 }
コード例 #20
0
ファイル: RssController.php プロジェクト: gitaminhq/gitamin
 public function show($owner, $project, $branch)
 {
     $repository = $project->getRepository();
     if ($branch === null) {
         $branch = $repository->getHead();
     }
     $commits = $repository->getPaginatedCommits($branch);
     return Response::make(View::make('projects/rss')->withProject($project)->withBranch($branch)->withCommits($commits), 200, ['Content-Type' => 'application/rss+xml']);
 }
コード例 #21
0
 /**
  * Returns css for the given path
  * 
  * @return \Illuminate\Support\Facades\Response
  */
 private function stylesheet($path)
 {
     $response = Response::make('', 304);
     if (!AssetCache::hasValidEtag($path)) {
         $response = Response::make(AssetCache::stylesheets($path), 200);
     }
     $response->header('Content-Type', 'text/css');
     $response->setEtag(AssetCache::getEtag($path));
     return $response;
 }
コード例 #22
0
ファイル: AuthFilter.php プロジェクト: baa-archieve/Cachet
 /**
  * Run the auth filter.
  *
  * We're verifying that the current user is logged in to Cachet.
  *
  * @param \Illuminate\Routing\Route $route
  * @param \Illuminate\Http\Request  $request
  *
  * @return \Illuminate\Http\Response|null
  */
 public function filter(Route $route, Request $request)
 {
     if (Auth::guest()) {
         if ($request->ajax()) {
             return Response::make('Unauthorized', 401);
         } else {
             return Redirect::guest('auth/login');
         }
     }
 }
コード例 #23
0
ファイル: ImageService.php プロジェクト: B1naryStudio/asciit
 public function get($filename)
 {
     $path = config('images.path') . $filename;
     if (!Storage::exists($path)) {
         throw new ImageNotFoundHttpException();
     }
     $data = Storage::get($path);
     $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
     return Response::make($data)->header('Content-Type', $mime)->header('Content-Length', strlen($data));
 }
コード例 #24
0
 public function getPicture($user)
 {
     if ($user->profile && $user->profile->picture) {
         return Response::download(storage_path('app/' . $user->profile->picture->filePath()));
     }
     if ($user->facebookUser) {
         return Response::make(file_get_contents('https://graph.facebook.com/' . $user->facebookUser->id . '/picture?type=large'))->header('Content-Type', 'image/jpeg');
     }
     return Response::download(storage_path('app/no_image.jpg'));
 }
コード例 #25
0
ファイル: Handler.php プロジェクト: alerj/parlamentojuvenil
 private function handleException($e)
 {
     if ($e instanceof AlreadySubscribed) {
         $view = $this->viewBuilder->buildViewData(view('2016.messages.already-subscribed'));
         return Response::make($view);
     }
     if ($e instanceof NotFoundHttpException) {
         return Response::make(view('errors.404'));
     }
 }
コード例 #26
0
ファイル: Json.php プロジェクト: vespakoen/epi
 public function respond($result, $status)
 {
     if ($result instanceof Model || $result instanceof Collection) {
         $result = $result->toArray();
     }
     if (Input::has('prettyprint')) {
         return Response::make(json_encode($result, JSON_PRETTY_PRINT), $status, array('content-type' => 'application/json'));
     }
     return Response::json($result, $status);
 }
コード例 #27
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if (config('typicms.auth_public') && !Auth::check()) {
         if ($request->ajax()) {
             return Response::make('Unauthorized', 401);
         }
         return Redirect::guest(route('login'));
     }
     return $next($request);
 }
コード例 #28
0
ファイル: Responder.php プロジェクト: vinelab/api-manager
 /**
  * @param $response
  * @param $status
  * @param $headers
  * @param $options
  *
  * @return $this|\Illuminate\Http\JsonResponse
  */
 public function respond($response, $status, $headers, $options)
 {
     switch ($this->getRequestFormat()) {
         case 'html':
         case 'text/html':
             return Response::make($response, $status, $headers, $options)->header('Content-Type', 'text/html');
         default:
             // whether 'Content-Type' is NULL or equal to anything such as 'application/json' response will be JSON
             return Response::json($response, $status, $headers, $options);
     }
 }
コード例 #29
0
ファイル: SessionAdmin.php プロジェクト: BrynnLawson/smarka
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // Check for session authentication
     if (session('password') == getenv('MAIL_PASSWORD') && session('email') == getenv('MAIL_USERNAME')) {
         return $next($request);
     } else {
         // We don't need to be descriptive because only admins should
         // ever get this response.
         return Response::make("401 Unauthorized", 401);
     }
 }
コード例 #30
0
 public function getFaculty()
 {
     $input = Input::get('option');
     $faculty = self::$factory->callWebservice(['query' => ['service' => 'getAllFaculty', 'idUniversity' => $input]]);
     $item = array();
     $item[0] = [0, 'ส่วนกลาง CENTER'];
     foreach ($faculty['data'] as $data) {
         $item[$data['ID_FACULTY']] = [$data['ID_FACULTY'], $data['NAME_THA'] . ' ' . $data['NAME_ENG']];
     }
     return Response::make($item);
 }