header() public static method

Retrieve a header from the request.
public static header ( string $key = null, string | array | null $default = null ) : string | array
$key string
$default string | array | null
return string | array
Example #1
0
 /**
  * Retrieve the authenticated User.
  *
  * @param  Request  $request
  * @return App\Models\User|bool
  */
 public function getUser($request)
 {
     $uid = $request->header('ID');
     $token = $request->header('X-Auth-Token');
     $user = Sentinel::findById($uid);
     if ($user->api_token == $token) {
         return $user;
     }
     return false;
 }
Example #2
0
 public static function user()
 {
     if (self::$user !== false) {
         return self::$user;
     }
     FacebookSession::setDefaultApplication(\Config::get('fb-auth::config.facebook_app_id'), \Config::get('fb-auth::config.facebook_secret'));
     $token = \Input::get('accessToken');
     if (!$token) {
         $token = \Request::header('FB-Access-Token');
     }
     if (!$token) {
         self::$user = null;
         return null;
     }
     $session = new FacebookSession($token);
     try {
         $me = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
         self::$user = \User::from_fb($me);
     } catch (FacebookAuthorizationException $e) {
         self::$user = null;
     } catch (FacebookRequestException $e) {
         self::$user = null;
     } catch (\Exception $e) {
         self::$user = null;
     }
     return self::$user;
 }
 public function login(User $user, Request $request)
 {
     $response = array();
     $cell = \Input::get('cell');
     $password = \Input::get('password');
     $data = UserNew::where('cellphone', '=', $cell)->first();
     $device = \Request::header('User-Agent');
     if (sizeof($data) > 0) {
         $key = $data->api_key;
     } else {
         $key = "no key";
     }
     if (sizeof($data) > 0) {
         $response["error"] = false;
         $response['name'] = $data->name;
         $response['cell_no'] = $data->cellphone;
         $response['apiKey'] = $data->api_key;
         $response['api_key'] = $key;
         $response['createdAt'] = $data->created_at;
         \Log::info("Login Device:" . $device . ", User Cell:" . $cell . ", User Names:" . $data->name);
     } else {
         $response['error'] = true;
         $response['message'] = 'Login failed. Incorrect credentials';
     }
     return \Response::json($response);
 }
Example #4
0
 /**
  * Redirect back, with a fallback if no previous page.
  *
  * @param string $fallback
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 protected function redirectBackWithFallback($fallback = '/')
 {
     if (!Request::header('referer')) {
         return Redirect::to($fallback);
     }
     return Redirect::back();
 }
Example #5
0
 /**
  * @return bool
  */
 protected function isDiscoveryRequest()
 {
     //This field contains a semicolon-separated list of representation schemes
     //which will be accepted in the response to this request.
     $accept = Request::header('Accept');
     return strstr($accept, XRDSDocumentBuilder::ContentType) !== false;
 }
 public function register_visualization($document_id)
 {
     $documento = \Documento::find($document_id);
     if (!$documento) {
         return \Response::json(['error' => 'No existe ningun documento con id = ' . $document_id], 200);
     }
     $auth_token = \Request::header('authorization');
     $user = \User::where('auth_token', '=', $auth_token)->first();
     $idevento = \Input::get('session_id');
     if ($idevento) {
         $evento = \Evento::find($idevento);
         if (!$evento) {
             return \Response::json(['error' => 'No existe ninguna sesión con id = ' . $idevento], 200);
         }
         $v = new \Visualizacion();
         $v->idusers = $user->id;
         $v->ideventos = $evento->ideventos;
         $v->iddocumentos = $document_id;
         $v->save();
     } else {
         // obtener todos los eventos asociados al documento
         $eventos = \DocumentosEvento::where('iddocumentos', '=', $document_id)->get();
         foreach ($eventos as $evento) {
             $v = new \Visualizacion();
             $v->idusers = $user->id;
             $v->ideventos = $evento->ideventos;
             $v->iddocumentos = $document_id;
             $v->save();
         }
     }
     return \Response::json(['success' => 1], 200);
 }
Example #7
0
 /**
  * Store a newly created upload in storage.
  *
  * @return Response
  */
 public function store()
 {
     Upload::setRules('store');
     if (!Upload::canCreate()) {
         return $this->_access_denied();
     }
     $file = Input::file('file');
     $hash = md5(microtime() . time());
     $data = [];
     $data['path'] = public_path() . '/uploads/' . $hash . '/';
     mkdir($data['path']);
     $data['url'] = url('uploads/' . $hash);
     $data['name'] = preg_replace('/[^a-zA-Z0-9_.-]/', '_', $file->getClientOriginalName());
     $data['type'] = $file->getMimeType();
     $data['size'] = $file->getSize();
     $data['uploadable_type'] = Request::header('X-Uploader-Class');
     $data['uploadable_id'] = Request::header('X-Uploader-Id') ? Request::header('X-Uploader-Id') : 0;
     $data['token'] = Request::header('X-CSRF-Token');
     $file->move($data['path'], $data['name']);
     if (property_exists($data['uploadable_type'], 'generate_image_thumbnails')) {
         Queue::push('ThumbnailService', array('path' => $data['path'] . '/' . $data['name']));
     }
     $upload = new Upload();
     $upload->fill($data);
     if (!$upload->save()) {
         return $this->_validation_error($upload);
     }
     if (Request::ajax()) {
         return Response::json($upload, 201);
     }
     return Redirect::back()->with('notification:success', $this->created_message);
 }
function userId()
{
    $token = explode(' ', Request::header('Authorization'))[1];
    $payloadObject = JWT::decode($token, Config::get('secrets.TOKEN_SECRET'));
    $payload = json_decode(json_encode($payloadObject), true);
    return $payload['sub'];
}
Example #9
0
 function is_pjax_request()
 {
     if (isset(Request::header('X-PJAX-CONTAINER'))) {
         return true;
     }
     return false;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     if ($body = \Request::input('body')) {
         $translation = Translation::where('body', $body)->first();
         if ($translation) {
             $response = response()->json([['id' => $translation->getId(), 'body' => $translation->body]]);
         } else {
             $response = response()->json(['errors' => ['The translation hasn\'t found.']], 404);
         }
     } else {
         if ($autocomplete = \Request::input('autocomplete')) {
             $translations = Translation::select('body')->where('body', 'LIKE', "{$autocomplete}%")->take(\Request::header('Limit') ?: 5)->get();
             if (count($translations) > 0) {
                 $response = response()->json($translations);
             } else {
                 $response = response()->json(['errors' => ['The matched translations haven\'t found.']], 404);
             }
         } else {
             $result = Translation::paginate(\Request::header('Limit') ?: 10);
             $headers['Current-Page'] = $result->currentPage();
             $headers['Last-Page'] = $result->lastPage();
             $translations = [];
             foreach ($result as $key => $item) {
                 $translations[$key]['id'] = $item->getId();
                 $translations[$key]['body'] = $item->body;
             }
             if (count($translations) > 0) {
                 $response = response()->json($translations, 200, $headers);
             } else {
                 $response = response()->json(['errors' => ['there aren\'t any translations.']], 404);
             }
         }
     }
     return $response;
 }
 /**
  * Handle an incoming request.
  * @param $request
  * @param callable $next
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  * @throws UnLoginException
  */
 public function handle($request, Closure $next)
 {
     $resource = $this->processPermissionResource($request);
     $url = "/auth/";
     if ($resource == null || $this->user == null) {
         //            return redirect($url);
         throw new UnLoginException("没有登录", 10001, array("url" => $url));
     }
     $admin = DeepinAuthAdministrator::find($this->user->getUid());
     if (!$admin instanceof DeepinAuthAdministrator) {
         return redirect($url);
         //用户已经被删除
     }
     if (intval($admin->uid()) != 1) {
         //只有这个用户可以免除所有的权限验证
         $isOk = $this->checkPermission($admin, $resource);
         //检查权限
         if ($isOk == false) {
             $url = \Request::header("Referer");
             if (empty($url)) {
                 $url = "/admin/app";
             }
             //                return redirect($url);
             throw new UnLoginException("没有权限", 10002, array("url" => $url));
         }
     }
     return $next($request);
 }
Example #12
0
 /**
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     // Use content negotiation to determine the correct format to return
     $negotiator = new \Negotiation\FormatNegotiator();
     $acceptHeader = Request::header('accept');
     // Set priorities to json (if the app requests json provide it in favor of html)
     $priorities = array('application/json', 'text/html', '*/*');
     // Get the best appropriate content type
     $result = $negotiator->getBest($acceptHeader, $priorities);
     // Default to html if $result is not set
     $val = "text/html";
     if (isset($result)) {
         $val = $result->getValue();
     }
     // See what kind of content we should return
     switch ($val) {
         case "text/html":
             // In case we want to return html, just let
             // Laravel render the view and send the headers
             return Response::view('route.planner')->header('Content-Type', "text/html")->header('Vary', 'accept');
             break;
         case "application/json":
         default:
             // In case we want to return JSON(LD) or something else, generate
             // our JSON by calling our static function 'getJSON()'
             return Response::make($this::getJSON())->header('Content-Type', "application/json")->header('Vary', 'accept');
             break;
     }
 }
Example #13
0
 public function __construct()
 {
     $token = Request::header('X-Auth-Token');
     $this->user = json_decode(AuthToken::validate($token));
     $this->page = Input::get('page');
     $this->per_page = Input::get('per_page');
 }
Example #14
0
 /**
  * Creates a Laravel route, returning a closure which passes the raw input to AngularPHP and returns the response
  */
 protected function init()
 {
     $route = func_get_arg(0);
     $this->setErrorHandler(function (\Exception $e, Request $r) {
         \Log::error($e, $r->toArray());
     });
     $endpoint = $this;
     \Route::any($route, function () use($endpoint) {
         $path = '/' . \Request::path();
         $referrer = \Request::header('referer');
         $host = \Request::header('host');
         if (($origin = \Request::header('Origin')) && count($this->corsHosts)) {
             $this->setCorsOrigin($origin);
         }
         /**
          * If being called remotely, add the domain name to the URI
          */
         if (strlen($referrer) && parse_url($referrer, PHP_URL_HOST) != $host) {
             $uri = '//' . $host . $path;
         } else {
             $uri = $path;
         }
         $request = new Request(\Request::json()->all());
         $response = $endpoint->setUri($uri)->execute($request, \Request::getMethod());
         return \Response::make($response->content, $response->code, $response->headers)->header('Content-Type', $response->contentType);
     });
 }
Example #15
0
 public function __construct()
 {
     //not sure
     $token = Request::header('X-Auth-Token');
     $this->user = json_decode(AuthToken::validate($token));
     $this->api_token = Input::get('api_token');
     //end not sure
 }
Example #16
0
 protected function getAuthToken()
 {
     $token = \Request::header('X-Auth-Token');
     if (empty($token)) {
         $token = \Input::get('auth_token');
     }
     return $token;
 }
 /**
  * Check request header for correct xAPI version
  **/
 public function checkVersion($route, $request)
 {
     //should be X-Experience-API-Version: 1.0.0 or 1.0.1 (can accept 1.0), reject everything else.
     $version = \Request::header('X-Experience-API-Version');
     if (!isset($version) || ($version < '1.0.0' || $version > '1.0.99') && $version != '1.0') {
         return $this->returnSuccessError(false, 'This is not an accepted version of xAPI.', '400');
     }
 }
Example #18
0
 public function index()
 {
     $user = Auth::user();
     $header = Request::header('User-Agent');
     //		if ($header == 'android 1.0.1')
     //			return $this->respondWithCustomStatusCode('Update', 452, 452);
     return $this->respond(['show_phone' => (int) $user->show_phone, 'show_email' => (int) $user->show_email, 'show_car_number' => (int) $user->show_car_number, 'enable_carchats' => (int) $user->enable_carchats, 'push_pm' => (int) $user->push_pm, 'push_comments' => (int) $user->push_comments, 'push_comment_likes' => (int) $user->push_comment_likes, 'push_post_likes' => (int) $user->push_post_likes]);
 }
Example #19
0
 private function getDevice()
 {
     $header = Request::header('Authorization');
     preg_match('#^Bearer\\s+(.*?)$#', $header, $matches);
     $authToken = $matches[1];
     $device = Device::where('auth_token', $authToken)->first();
     return $device;
 }
Example #20
0
 /**
  * Display a listing of the resource.
  * GET /cities
  *
  * @return Response
  */
 public function index()
 {
     $locale = in_array(Request::header('Locale'), $this->avaibleLocales) ? Request::header('Locale') : 'ru';
     $cities = CityRef::all();
     foreach ($cities as $city) {
         $result[] = ['name' => $city->{$locale}, 'id' => $city->id];
     }
     return $this->respond($result);
 }
Example #21
0
 public function __construct()
 {
     $token = Request::header('X-Auth-Token');
     $this->user = json_decode(AuthToken::validate($token));
     $this->api_token = Input::get('api_token');
     $this->page = Input::get('page');
     $this->per_page = Input::get('per_page');
     $this->type = Input::get('type');
     $this->dbConnect = Helpers::dbConnect();
 }
Example #22
0
 /**
  * Gets a header from the request headers.
  * @param  $key Header to be returned.
  * @param  $default Value to be returned if the header is not set.
  * @return mixed Value of the header.
  */
 public function header($key, $default = null)
 {
     $value = \Request::header($key);
     // If the key is set in the headers then return it.
     if (isset($value)) {
         return $value;
     } else {
         return $this->getParam($key, $default);
     }
 }
Example #23
0
 public static function getClientIpAddress()
 {
     $header = \Request::header();
     if (array_key_exists('X-Forwarded-For', $header) && !empty($header['X-Forwarded-For'])) {
         return $header['X-Forwarded-For'];
     }
     if (\Config::get('app.debug')) {
         return '121.122.2.245';
     }
     return \Request::getClientIp();
 }
Example #24
0
 public function updateUser()
 {
     $token = explode(' ', Request::header('Authorization'))[1];
     $payloadObject = JWT::decode($token, Config::get('secrets.TOKEN_SECRET'));
     $payload = json_decode(json_encode($payloadObject), true);
     $user = User::find($payload['sub']);
     $user->displayName = Input::get('displayName', $user->displayName);
     $user->email = Input::get('email', $user->email);
     $user->save();
     $token = $this->createToken($user);
     return Response::json(array('token' => $token));
 }
 public function __construct()
 {
     // 判断浏览器名称和版本
     $agent = Request::header('user-agent');
     $browser = '';
     $browser_ver = '';
     if (preg_match('/MSIE\\s([^\\s|;]+)/i', $agent, $regs)) {
         $browser = 'Internet Explorer';
         $browser_ver = $regs[1];
     } elseif (preg_match('/FireFox\\/([^\\s]+)/i', $agent, $regs)) {
         $browser = 'FireFox';
         $browser_ver = $regs[1];
     } elseif (preg_match('/Maxthon/i', $agent, $regs)) {
         $browser = '(Internet Explorer ' . $browser_ver . ') Maxthon';
         $browser_ver = '';
     } elseif (preg_match('/Opera[\\s|\\/]([^\\s]+)/i', $agent, $regs)) {
         $browser = 'Opera';
         $browser_ver = $regs[1];
     } elseif (preg_match('/OmniWeb\\/(v*)([^\\s|;]+)/i', $agent, $regs)) {
         $browser = 'OmniWeb';
         $browser_ver = $regs[2];
     } elseif (preg_match('/Netscape([\\d]*)\\/([^\\s]+)/i', $agent, $regs)) {
         $browser = 'Netscape';
         $browser_ver = $regs[2];
     } elseif (preg_match('/safari\\/([^\\s]+)/i', $agent, $regs)) {
         $browser = 'Safari';
         $browser_ver = $regs[1];
     } elseif (preg_match('/NetCaptor\\s([^\\s|;]+)/i', $agent, $regs)) {
         $browser = '(Internet Explorer ' . $browser_ver . ') NetCaptor';
         $browser_ver = $regs[1];
     } elseif (preg_match('/Lynx\\/([^\\s]+)/i', $agent, $regs)) {
         $browser = 'Lynx';
         $browser_ver = $regs[1];
     }
     if ($browser == 'Internet Explorer' && $browser_ver <= 8) {
         if (!Request::ajax()) {
             throw new BrowserNotSupportedException('浏览器不兼容');
         }
     }
     if (!Config::get('constants.installed') && !Request::is('install/*') && !Request::is('api/install')) {
         if (!Request::ajax()) {
             throw new AppNeedInstallException('应用未初始化');
         }
     }
     if (Auth::check()) {
         $this->CurrentUser = Auth::user();
         $this->CurrentUser->updateAct();
     } else {
         $this->CurrentUser = new AmaotoUser();
     }
     View::share('CurrentUser', $this->CurrentUser);
 }
Example #26
0
 public static function extractFromHeader()
 {
     $access_token = "";
     $authorization = \Request::header('Authorization');
     if (is_null($authorization) and function_exists('apache_request_headers')) {
         $headers = apache_request_headers();
         $authorization = isset($headers['Authorization']) ? $headers['Authorization'] : null;
     }
     if (!is_null($authorization)) {
         $access_token = str_replace('Bearer ', '', $authorization);
     }
     return $access_token;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     if ($body = \Request::input('body')) {
         $result = Word::with('position', 'translations')->where('body', $body)->orderBy('position_id', 'DESC')->get();
         $exercises = \Auth::user()->exercises;
         $words = [];
         foreach ($result as $key => $item) {
             $words[$key]['id'] = $item->getId();
             $words[$key]['body'] = $item->body;
             $words[$key]['ts'] = $item->ts;
             $words[$key]['position'] = $item->position ? $item->position->body : null;
             $words[$key]['used'] = $exercises->contains('word_id', $item->id);
             $words[$key]['translations'] = [];
             foreach ($item->translations as $_key => $translation) {
                 $words[$key]['translations'][$_key]['id'] = $translation->getId();
                 $words[$key]['translations'][$_key]['body'] = $translation->body;
             }
         }
         if (count($words) > 0) {
             $response = response()->json($words);
         } else {
             $response = response()->json(['errors' => ['The word hasn\'t found.']], 404);
         }
     } else {
         if ($autocomplete = \Request::input('autocomplete')) {
             $words = Word::select('body')->where('body', 'LIKE', "{$autocomplete}%")->groupBy('body')->take(\Request::header('Limit') ?: 5)->get();
             if (count($words) > 0) {
                 $response = response()->json($words);
             } else {
                 $response = response()->json(['errors' => ['The matched words haven\'t found.']], 404);
             }
         } else {
             $result = Word::with('position')->paginate(\Request::header('Limit') ?: 10);
             $headers['Current-Page'] = $result->currentPage();
             $headers['Last-Page'] = $result->lastPage();
             $words = [];
             foreach ($result as $key => $item) {
                 $words[$key]['id'] = $item->getId();
                 $words[$key]['body'] = $item->body;
                 $words[$key]['ts'] = $item->ts;
                 $words[$key]['position'] = $item->position ? $item->position->body : null;
             }
             if (count($words) > 0) {
                 $response = response()->json($words, 200, $headers);
             } else {
                 $response = response()->json(['errors' => ['there aren\'t any words.']], 404);
             }
         }
     }
     return $response;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $user = \Auth::user();
     $scope = $user->exercises()->with('word.position', 'word.translations', 'translations');
     $readingFlag = \Request::input('reading');
     $memoryFlag = \Request::input('memory');
     $checkFlag = \Request::input('check');
     $headers = [];
     if ($readingFlag || $memoryFlag || $checkFlag) {
         $lessonSize = $user->lesson_size;
         if ($readingFlag) {
             $scope->where('status', 'new')->where('reading', '!=', 0)->where('memory', '!=', 0);
         } else {
             if ($memoryFlag) {
                 $scope->where('status', 'new')->where('reading', 0)->where('memory', '!=', 0);
             } else {
                 if ($checkFlag) {
                     $scope->where('status', 'old')->where('check_at', '<', date_create());
                 }
             }
         }
         $result = $scope->orderBy('updated_at', 'ASC')->take($lessonSize)->get();
     } else {
         if (\Request::input('random')) {
             if ($excludedId = \Request::input('excluded_id')) {
                 $scope->where('id', '!=', $excludedId);
             }
             $result = $scope->orderByRaw('RAND()')->take(\Request::header('Limit') ?: 5)->get();
         } else {
             if ($search = \Request::input('search')) {
                 $scope->whereHas('word', function ($query) use($search) {
                     $query->where('body', 'LIKE', "{$search}%");
                 });
             }
             $result = $scope->orderBy('updated_at', 'DESC')->paginate(\Request::header('Limit') ?: 10);
             $headers['Current-Page'] = $result->currentPage();
             $headers['Last-Page'] = $result->lastPage();
         }
     }
     $exercises = [];
     foreach ($result as $key => $item) {
         $exercises[$key] = $item->view();
     }
     if (count($exercises) > 0) {
         $response = response()->json($exercises, 200, $headers);
     } else {
         $response = response()->json(['errors' => ['there aren\'t any exercises.']], 404);
     }
     return $response;
 }
Example #29
0
 private static function parseAuthHeader($headerName = 'Authorization', $method = 'bearer')
 {
     $header = Request::header($headerName);
     if (is_null($header)) {
         $headers = array_change_key_case(getallheaders(), CASE_LOWER);
         if (array_key_exists($headerName, $headers)) {
             $header = $headers[$headerName];
         }
     }
     if (!starts_with(strtolower($header), $method)) {
         return false;
     }
     return trim(str_ireplace($method, '', $header));
 }
Example #30
0
 /**
  * Retrieve one or more headers from request.
  *
  * Note: Returns all headers, if no keys array is provided.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param array $keys
  *
  * @return array
  */
 function headers(array $keys = [])
 {
     // Retrieve all request headers
     $requestHeaders = \Request::header();
     // Convert all values to lowercase
     $keys = array_map('strtolower', $keys);
     // Found headers container
     $headers = [];
     foreach ($requestHeaders as $requestHeader => $value) {
         if (!empty($keys) && !in_array($requestHeader, $keys)) {
             continue;
         }
         // Add to headers container
         $headers[$requestHeader] = implode(';', $value);
     }
     return $headers;
 }