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')); }
/** * Tracker update application * * 1. Check input * 2. Check auth * 3. Set current absence * @return Response */ function updateversion() { $attributes = Input::only('application'); //1. Check input if (!$attributes['application']) { return Response::json('101', 200); } if (!isset($attributes['application']['api']['client']) || !isset($attributes['application']['api']['secret']) || !isset($attributes['application']['api']['tr_ver']) || !isset($attributes['application']['api']['station_id']) || !isset($attributes['application']['api']['email']) || !isset($attributes['application']['api']['password'])) { return Response::json('102', 200); } //2. Check auth $client = \App\Models\Api::client($attributes['application']['api']['client'])->secret($attributes['application']['api']['secret'])->workstationaddress($attributes['application']['api']['station_id'])->with(['branch'])->first(); if (!$client) { $filename = storage_path() . '/logs/appid.log'; $fh = fopen($filename, 'a+'); $template = date('Y-m-d H:i:s : Login : '******'application']['api']) . "\n"; fwrite($fh, $template); fclose($fh); return Response::json('402', 200); } //3. Set current absence if ((double) $attributes['application']['api']['tr_ver'] < (double) Config::get('current.absence.version')) { return Response::json('sukses|' . Config::get('current.absence.url1') . '|' . Config::get('current.absence.url2'), 200); } return Response::json('200', 200); }
/** * 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]); } }
/** * 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); } }
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); }
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']); }
/** * 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']); } }
/** * * @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; } }
/** * Upload attachment to storage * * @return Response */ public function store(Request $request) { if (!Session::has('questions_hash')) { Session::put('questions_hash', md5(time())); } return Response::json(['attachment' => \QuestionsService::uploadAttachment($request->file('upl'))]); }
public function createAndStartNewStream($arrData) { $stream = $this->stream->first(); $stream->update($arrData); event(new StreamEvent($stream->streaming)); return Response::json(['success' => true, 'isStreaming' => $stream->streaming]); }
/** * 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) { if ($e instanceof ModelNotFoundException) { return Response::json(['error' => ['message' => 'Resource not found']], 404); } return parent::render($request, $e); }
public function catalogo() { $cliente_id = User::where('email', Input::get('email'))->get()[0]->load('miembrosDe')['miembrosDe'][0]->cliente_id; $catalogo = Catalogos::find(Input::get('catalogo_id'))->load('menu')['menu']; $catalogo = $this->preparoCatalogo($catalogo); return Response::json($catalogo); }
public function doDelelePhrase() { $id_record = Input::get("id"); Trans::find($id_record)->delete(); Trans::reCacheTrans(); return Response::json(array('status' => 'ok')); }
/** * POST /api/login */ public function login() { // Get all data send in post $loginFormData = Request::all(); // Create rules for the validator $validator = Validator::make($loginFormData, ['user_email' => 'required|email', 'user_password' => 'required']); // If validator fails return a 404 response if ($validator->fails()) { return Response::json(['status_code' => 404, 'errors' => $validator->errors()->all()], 404); } $user = User::where('email', '=', strtolower($loginFormData['user_email']))->first(); if (!$user) { return Response::json(['status_code' => 404, 'errors' => ['Votre compte est introuvable dans notre base de donnée.']], 404); } else { if ($user->activated == 0) { return Response::json(['status_code' => 404, 'errors' => ["Merci d'activer votre compte."]], 404); } else { if (!Hash::check($loginFormData['user_password'], $user->password)) { return Response::json(['status_code' => 404, 'errors' => ["Votre mot de passe est incorrect."]], 404); } } } $room = Room::find($user->room_id); $partner = User::find($user->is_partner ? $room->user_id : $room->partner_id); if ($partner->activated == 0) { return Response::json(['status_code' => 404, 'errors' => ["Le compte de votre partenaire n'a pas été activé."]], 404); } // Success return Response::json(['status_code' => 200, 'success' => "Login success", 'data' => ['me' => $user, 'partner' => $partner, 'room' => $room]]); }
/** * 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); }
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 }
/** * @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)); }
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 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' => '用户暂未激活']); } }
/** * 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 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)); }
public function customer(UserInterface $user) { if (Gate::allows('is_customer', $user->getCustomer())) { return Response::json(['data' => $user->getCustomer()->entries]); } return Response::json([], 401); }
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')); } }
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); } }
/** * 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(); } }
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)]); }
/** * 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); } }
/** * 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 delete() { $id = Input::get('id'); $this->model = Terrain::find($id); $this->model->delete(); return Response::json(['success' => true]); }
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); } }