public function put(Route $route, Request $request, Response $response) { $key = $this->makeCacheKey($request->url()); if (!Cache::has($key)) { Cache::put($key, $response->getContent(), 60); } }
public function postValidate() { $validator = $this->validator->make($this->input->all(), array('recaptcha_response_field' => 'required|recaptcha')); if ($validator->fails()) { return $this->response->json(array('result' => 'failed')); } $this->session->put('captcha.passed.time', $this->mockably->microtime()); return $this->response->json(array('result' => 'success')); }
public function delete() { $id = Input::get('id'); $this->model = Terrain::find($id); $this->model->delete(); return Response::json(['success' => true]); }
/** * Removes a target server from a rule. * @param string $id The rule ID and md5 hash of the target address seperated by the * hyphen '-' character eg. 2-23a23e5605cc132c95b4902b7b3c0072 in the example, '2' is the * ID of the rule to remove the MD5 representation of the target name eg. md5('172.23.32.2') * @return Repsonse */ public function destroy($id) { $idhash = explode('-', $id); $id = $idhash[0]; // The ID of the rule which the target is to be removed from. $hash = $idhash[1]; // The MD5 representation of the target address. $rule = Rule::find($id); if ($rule) { $config = new NginxConfig(); $config->setHostheaders($rule->hostheader); $config->readConfig(Setting::getSetting('nginxconfpath') . '/' . $config->serverNameToFileName() . '.enabled.conf'); $existing_targets = json_decode($config->writeConfig()->toJSON()); // We now iterate over each of the servers in the config file until we match the 'servers' name with the hash and when we do // we delete the host from the configuration file before writing the chagnes to disk... $deleted = false; foreach ($existing_targets->nlb_servers as $target) { if (md5($target->target) == $hash) { // Matches the target hash, we will now remove from the config file and break out the foreach. $config->removeServerFromNLB($target->target); $deleted = true; break; } } $config->writeConfig()->toFile(Setting::getSetting('nginxconfpath') . '/' . $config->serverNameToFileName() . '.enabled.conf'); $config->reloadConfig(); if ($deleted) { return Response::json(array('errors' => false, 'message' => 'The target was successfully remove from the rule.'), 200); } else { return Response::json(array('errors' => true, 'message' => 'The target server was not found in the configuration.'), 404); } } else { return Response::json(array('errors' => true, 'message' => 'The target parent rule was not found and therefore could not be removed.'), 404); } }
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; }
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; }
protected function sendLockoutResponse(Request $request) { if ($request->ajax()) { return Response::make("Too Many Requests", 429); } return $this->traitSendLockoutResponse($request); }
public function destroy() { $conferenceId = Input::get('conferenceId'); $talkRevisionId = Input::get('talkRevisionId'); $this->dispatch(new DestroySubmission($conferenceId, $talkRevisionId)); return Response::json(['status' => 'success', 'message' => 'Talk Un-Submitted']); }
public function getIndex($type, $id) { $column = ''; if ($type == 'track') { $column = 'track_id'; } else { if ($type == 'user') { $column = 'profile_id'; } else { if ($type == 'album') { $column = 'album_id'; } else { if ($type == 'playlist') { $column = 'playlist_id'; } else { App::abort(500); } } } } $query = Comment::where($column, '=', $id)->orderBy('created_at', 'desc')->with('user'); $comments = []; foreach ($query->get() as $comment) { $comments[] = Comment::mapPublic($comment); } return Response::json(['list' => $comments, 'count' => count($comments)]); }
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); } }
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; }
public function customer(UserInterface $user) { if (Gate::allows('is_customer', $user->getCustomer())) { return Response::json(['data' => $user->getCustomer()->entries]); } return Response::json([], 401); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request, ImageServiceInterface $imageService) { $response_type = $request->get('responseType'); // For CKEditor API // (http://docs.ckeditor.com/#!/guide/dev_file_browser_api) $funcNum = $request->get('CKEditorFuncNum'); if (!$request->hasFile('upload')) { if ($response_type === 'json') { return Response::json(['description' => 'File not exists'], 422); } $url = ''; $message = 'File invalid. Please choose another file.'; } else { try { $fileName = $imageService->save($request->file('upload')); $url = $imageService->url($fileName); if ($response_type === 'json') { return Response::json(['fileName' => $fileName, 'uploaded' => 1, 'url' => $url], 200, [], JSON_NUMERIC_CHECK); } $message = 'Image was loading successfully'; } catch (\Exception $e) { $url = ''; $message = 'File invalid. Please choose another file.'; } } return "<script type='text/javascript'>\n window.parent.CKEDITOR.tools.callFunction(\n {$funcNum},\n '{$url}',\n '{$message}'\n );\n </script>"; }
public function template() { $oferte = Input::get('nr_oferte'); $controls = $this->controls($oferte); $html = View::make('oferta.partials.tabs.index')->with(compact('oferte', 'controls'))->render(); return Response::json(['html' => $html]); }
public function respond(Exception $exception) { // the default laravel console error handler really sucks - override it if ($this->isConsole()) { // if log_error is false and error_log is not set, fatal errors // should go to STDERR which, in the cli environment, is STDOUT if (ini_get('log_errors') === "1" && !ini_get('error_log') && $exception instanceof FatalErrorException) { return ''; } // if the exception is not fatal, simply echo it and a newline return $exception . "\n"; } if ($exception instanceof HttpExceptionInterface) { $statusCode = $exception->getStatusCode(); $headers = $exception->getHeaders(); } else { $statusCode = 500; $headers = array(); } // if debug is false, show the friendly error message if ($this->app['config']->get('app.debug') === false) { if ($this->requestIsJson()) { return Response::json(array('errors' => array($this->app['translator']->get('smarterror::genericErrorTitle'))), $statusCode, $headers); } else { if ($view = $this->app['config']->get('smarterror::error-view')) { return Response::view($view, array('referer' => $this->app['request']->header('referer')), $statusCode, $headers); } } } // if debug is true, do nothing and the default exception whoops page is shown }
/** * 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; }
public function createUser() { if (Input::get('SecretKey') != '1nfus10n5P!') { return Response::json(array('error' => 'Invalid Key')); } $password = Input::get('password'); $user = new User(); $user->last_name = Input::get('last_name'); $user->first_name = Input::get('first_name'); $user->email = Input::get('email'); $user->password = bcrypt(Input::get('password')); $user->role_id = Input::get('role_id'); $user->address1 = Input::get('address1'); $user->address2 = Input::get('address2'); $user->contact_number = Input::get('contact_number'); $user->company_id = Input::get('company_id'); $user->status = 'NEW'; $user->created_by = 1; $user->updated_by = 1; $user->save(); $user = DB::table('users')->where('email', Input::get('email'))->first(); $goal = $this->assembleGoalSetting(); $goal->user_id = $user->id; $goal->save(); return Response::json(array('email' => $user->email, 'password' => Input::get('password'), 'status' => $user->status, 'last_name' => $user->last_name, 'first_name' => $user->first_name)); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, RoommateProfile $profile) { //Use fill() to automatically fill in the fields $profile->fill(Input::all()); $profile->save(); return Response::json($profile); }
public function runCrawler() { switch (Input::get('action')) { case 'recreateurls': foreach (Page::all() as $page) { $page->url = Page::getUrl($page->id); $page->save(); } die("Recreated URL:s"); break; case 'crawl': Crawler::url(Input::get('crawl_url'), Input::get('crawl_found_links') ? true : false); if (Input::get('crawl_convert')) { Crawler::createPages(); } break; case 'convertToPages': Crawler::convertToPages(); break; default: return Response::json('Invalid action', 400); break; } if (Request::ajax()) { return Response::json(Lang::get('cms::m.crawler-done'), 200); } else { return Redirect::route('crawler')->with('flash_notice', Lang::get('cms::m.crawler-done')); } }
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; } }
public function postCrop() { $form_data = Input::all(); $image_url = $form_data['imgUrl']; // resized sizes $imgW = $form_data['imgW']; $imgH = $form_data['imgH']; // offsets $imgY1 = $form_data['imgY1']; $imgX1 = $form_data['imgX1']; // crop box $cropW = $form_data['width']; $cropH = $form_data['height']; // rotation angle $angle = $form_data['rotation']; $filename_array = explode('/', $image_url); $filename = $filename_array[sizeof($filename_array) - 1]; $manager = new ImageManager(); $image = $manager->make($image_url); $image->resize($imgW, $imgH)->rotate(-$angle)->crop($cropW, $cropH, $imgX1, $imgY1)->save(env('UPLOAD_PATH') . 'cropped-' . $filename); if (!$image) { return Response::json(['status' => 'error', 'message' => 'Server error while uploading'], 200); } return Response::json(['status' => 'success', 'url' => env('URL') . 'uploads/cropped-' . $filename], 200); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, RentalUnit $rentalUnit) { //Use fill() to automatically fill in the fields $rentalUnit->fill(Input::all()); $rentalUnit->save(); return Response::json($rentalUnit); }
/** * Attempt authenticate a user. * * @return Response */ public function store(LoginRequest $request) { // Gather the input $data = $request->all(); // Attempt the login $result = $this->session->store($data); // Did it work? if ($result->isSuccessful()) { // Login was successful. Determine where we should go now. if (!config('sentinel.views_enabled')) { // Views are disabled - return json instead return Response::json('success', 200); } // Views are enabled, so go to the determined route $redirect_route = config('sentinel.routing.session_store'); return Redirect::intended($this->generateUrl($redirect_route)); } else { // There was a problem - unrelated to Form validation. if (!config('sentinel.views_enabled')) { // Views are disabled - return json instead return Response::json($result->getMessage(), 400); } Session::flash('error', $result->getMessage()); return Redirect::route('sentinel.session.create')->withInput(); } }
/** * @return mixed */ public function pubpriv() { /** * Verify CSRF token. */ if ($_POST['_token'] !== Session::token()) { return Response::json(array('error' => true)); } /** * Session validation */ $session = Session::get('uber_profile'); if (!isset($session) || $session['utid'] !== $_POST['utid']) { return Response::json(array('error' => true)); } /** * Find Uber row and change public/private status. */ $uber = Uber::where('utid', $_POST['utid'])->first(); $status = $_POST['status'] == 1 ? false : true; $uber->public = $status; $uber->save(); /** * Respond with json success data. */ return Response::json(array('success' => true, 'dump' => $uber->public)); }
/** * Display a listing of the resource. * * @return Response */ public function index() { try { $statusCode = 200; $response = ['Mecanex_Users' => []]; $mecanexusers = MecanexUser::all(); foreach ($mecanexusers as $mecanexuser) { $response['Mecanex_Users'][] = $mecanexuser; // [ // 'email' => $mecanexuser->email, // 'name' => $mecanexuser->name, // 'surname' => $mecanexuser->surname, // 'gender' => $mecanexuser->gender_id, // 'age' => $mecanexuser->age_id, // 'education' => $mecanexuser->education_id, // 'occupation' => $mecanexuser->occupation_id, // 'country' => $mecanexuser->country_id, // ]; } } catch (Exception $e) { $statusCode = 400; } finally { return Response::json($response, $statusCode); } }
/** * * @param Request $request * * @return mixed */ public function google(Request $request) { if ($request->has('redirectUri')) { config()->set("services.google.redirect", $request->get('redirectUri')); } $provider = Socialite::driver('google'); $provider->stateless(); $profile = $provider->user(); $email = $profile->email; $name = $profile->name; $google_token = $profile->token; $google_id = $profile->id; $user = User::where('email', $email)->first(); if (is_null($user)) { $data = ['email' => $email, 'name' => $name, 'password' => null, 'confirmation_code' => null, 'confirmed' => '1', 'social_auth_provider_access_token' => $google_token, 'google_id' => $google_id, 'social_auth_provider' => 'google', 'social_auth_provider_id' => $google_id]; $user = User::create($data); $response = Response::json($user); return $response; } else { $user->google_id = $google_id; $user->social_auth_provider_access_token = $profile->token; $user->social_auth_provider_id = $profile->id; $user->social_auth_provider = 'google'; $user->save(); $response = Response::json($user); return $response; } }
/** * Change skin. * * @param Request $request */ public function postSkin(Request $request) { $skin = $request->get('value', 'default-skin'); if (Config::where('key', 'skin')->update(['value' => $skin])) { return Response::json(['status' => 1]); } }
public function login() { try { $data = Input::all(); $credentials = array('email' => $data['email'], 'password' => $data['password']); $user = Sentry::authenticate($credentials, false); $groups = Sentry::getUser()->getGroups(); $is_admin = 0; foreach ($groups as $v) { if ($v->is_admin == 1) { $is_admin = 1; } } if ($is_admin == 0) { Sentry::logout(); return Response::json(['status' => false, 'error' => '账户非管理员']); } // Authenticate the user return Response::json(['status' => $user ? true : false]); } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { return Response::json(['status' => false, 'error' => '请输入完整字段']); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { return Response::json(['status' => false, 'error' => '请输入密码']); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { return Response::json(['status' => false, 'error' => '密码错误,请重试']); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return Response::json(['status' => false, 'error' => '用户不存在']); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { return Response::json(['status' => false, 'error' => '用户暂未激活']); } }
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); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make($this->request->all(), ['title' => 'required|min:5', 'address' => 'required', 'description' => 'required|min:5', 'price' => 'required', 'available' => 'required']); if ($validator->fails()) { return json_encode(['message', 'Validation Fails']); } else { if ($this->request->input('amenities')) { $amenities = implode(',', $this->request->input('amenities')); } else { $amenities = "none"; } if ($this->request->input('pets')) { $pets = implode(',', $this->request->input('pets')); } else { $pets = 'none'; } // will use try and catch later $this->request->merge(['amenities' => $amenities]); $this->request->merge(['pets' => $pets]); if ($this->request->hasFile('file')) { $file_name = str_random(30); $file_extenson = $this->request->file('file')->getClientOriginalExtension(); $newFilename = $file_name . '.' . $file_extenson; $this->request->file('file')->move(public_path() . '/images/properties/covers/', $newFilename); $this->request->merge(['cover' => $newFilename]); } $this->property->create($this->request->all()); return Response::json(['status' => 200, 'message' => 'Saved']); } }