/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Auth::check()) {
         // If logged in, take the user's language setting
         $language = Auth::user()->language;
     } else {
         // If not logged in, rely on cookies
         if ($request->hasCookie('locale')) {
             // If cookie exists, use it
             $language = $request->cookie('locale');
         } else {
             // Otherwise, English is our default language
             $language = 'en';
         }
     }
     return $next($request)->withCookie(cookie()->forever('locale', $language));
 }
Example #2
0
 public function getModel()
 {
     if (\Auth::check()) {
         return \Auth::user();
     }
     if ($this->request->hasCookie('email_user')) {
         $user = Email::where('email', $this->request->cookie('email_user'));
     }
     if ($this->request->hasCookie('guest_user')) {
         $tracker = $this->request->cookie('guest_user');
     }
     $tracker = $this->request->getClientIp();
     $user = Guest::firstOrCreate(['identifier' => $tracker]);
     return $user;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  */
 public function handle(Request $request, Closure $next)
 {
     if ($this->app->isDownForMaintenance() && !in_array($request->getClientIp(), config('maintenance.ips', [])) && (config('maintenance.bypass_with_cookie', false) === false || config('maintenance.cookie_name', '') === '' || !$request->hasCookie(config('maintenance.cookie_name')))) {
         throw new HttpException(503);
     }
     return $next($request);
 }
Example #4
0
 public function handle(Request $request, Closure $next)
 {
     if ($request->hasCookie('lang')) {
         app()->setLocale($request->cookie('lang'));
     }
     return $next($request);
 }
Example #5
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->hasCookie('token')) {
         return redirect(route('login'))->withErrors(['generic' => ['You need to be logged in']])->withCookie(cookie('token', $request->cookie('token'), -1, null, null, false, true));
     }
     return $next($request);
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function getLocale()
 {
     if ($this->request->hasCookie('locale')) {
         return $this->request->cookie('locale');
     } else {
         return $this->getConfigDefaultLocale();
     }
 }
 /**
  * @return string $cookieToken
  */
 protected function findOrCreateTrackingCookieToken()
 {
     $cookieToken = str_random(40);
     if ($this->request->hasCookie(config('footprints.cookie_name'))) {
         $cookieToken = $this->request->cookie(config('footprints.cookie_name'));
     }
     $this->response->withCookie(cookie(config('footprints.cookie_name'), $cookieToken, config('footprints.attribution_duration')));
     return $cookieToken;
 }
Example #8
0
 /**
  * Display a listing of the resource.
  *
  * @param Request $request
  * @return Response
  */
 public function index(Request $request)
 {
     /**
      * Check if intro cookie is set
      */
     if (!$request->hasCookie('intro')) {
         return view('in');
     }
     return view('index');
 }
Example #9
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->hasCookie('uuid')) {
         return $next($request);
     } else {
         $uuid = Uuid::uuid4();
         $response = $next($request);
         return $response->withCookie(cookie()->forever('uuid', $uuid));
     }
 }
Example #10
0
 /**
  * This route is only valid for multi locale applications.
  *
  * @param Request $request
  * @param AccountManager $manager
  * @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
  */
 public function landing(Request $request, AccountManager $manager)
 {
     if ($manager->account()->locales->count() == 1) {
         return redirect()->to(store_route('store.home'));
     }
     if ($request->hasCookie('locale')) {
         return redirect()->to(store_route('store.home', [], [], $request->cookie('locale')));
     }
     return $this->theme->render('home.landing');
 }
 /**
  * @param Request $request
  * @param Closure $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     $shop = App::make('Shop');
     if ($request->hasCookie($shop->getSession()->getCookieName()) && $shop->getCart()->has(Cookie::get($shop->getSession()->getCookieName()))) {
         $shop->getCart()->updateExpire();
         return $next($request);
     } else {
         $hash = $shop->getSession()->genId();
         $shop->getCart()->create($hash);
         $shop->getSession()->create($hash);
         $response = $next($request);
         return $response->withCookie(cookie()->make($shop->getSession()->getCookieName(), $hash, $shop->getSession()->getCookieExpire()));
     }
 }
Example #12
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->hasCookie('token')) {
         //if we have a token, the user has been authed at some point
         $jwt = explode('.', $request->cookie('token'));
         //no need to validate signature, we just want the expirey
         $payload = json_decode(base64_decode($jwt[1]));
         if (time() >= $payload->exp) {
             //token has expired, logout
             //TODO, consider checking if refresh has expired too, and auto renew token seamlessly for user
             //TODO, is there a better way to remove cookie and redirect in L5 ->cookie->remove() did seem to work?
             return redirect(route('login'))->withErrors(['generic' => ['Your session has expired, please login again']])->withCookie(cookie('token', $request->cookie('token'), -1, null, null, false, true));
         }
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // If we do not have a logged in user, check for an authorized JWT
     if (!Auth::check()) {
         // If there is a JWT cookie, grab it
         if ($request->hasCookie('jwt')) {
             $jwt = $request->cookie('jwt');
             // If the JWT is not null, and is too long to be an error message, try to retrieve a user from it
             if ($jwt != null && strlen($jwt) > 35) {
                 try {
                     $user = JWTAuth::toUser($jwt);
                 } catch (JWTException $e) {
                     $user = null;
                 }
                 // If the JWT was valid, and a user was returned from it, log them in
                 if ($user instanceof User) {
                     Auth::login($user);
                 }
             }
         }
     }
     return $next($request);
 }
Example #14
0
 /**
  * Creates a new user.
  * This is a generic user.store function adapted from a previous project
  * and should definitely be brought up to date with this project /
  * adapted so that we can use Laravel Socialite with it.
  *
  *
  * 	Data should be POSTed to this function only
  * @return REDIRECT home
  */
 public function store(Request $request)
 {
     // Only allow following fields to be submitted
     $data = Request::only(['name', 'password', 'password_confirmation', 'email', 'username', 'bio', 'city', 'country']);
     if ($request->hasFile('profile_picture')) {
         $data['profile_picture'] = MediaController::uploadImage($request->file('profile_picture'), time(), $directory = "user", $bestFit = true, $fitDimensions = [500, 500]);
     }
     // Validate all input
     $validator = Validator::make($data, ['name' => 'required', 'email' => 'email|required|unique:users', 'password' => 'required|confirmed|min:5', 'username' => 'required|unique:users|min:4']);
     if ($validator->fails()) {
         // If validation fails, redirect back to
         // registration form with errors
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $data['language'] = $request->hasCookie('locale') ? $request->cookie('locale') : 'en';
     $newUser = createUser($data);
     if ($newUser) {
         Auth::login($newUser);
         // If successful, go to home
         return Redirect::route('home');
     }
     // If unsuccessful, return with errors
     return Redirect::back()->withErrors(['message' => 'We\'re sorry but registration failed, please try again later.'])->withInput();
 }
Example #15
0
 public function fromCookie(Request $request)
 {
     $this->setLocale($request->cookie('settings_locale'));
     $this->setCountry($request->cookie('settings_country'));
     $this->setTimezone($request->cookie('settings_timezone'));
     $this->setCurrency($request->cookie('settings_currency'));
     $this->setNumberFormat($request->cookie('settings_number_format'));
     $this->setFirstDayOfWeek($request->cookie('settings_first_day_of_week'));
     $this->setLongDateFormat($request->cookie('settings_long_date_format'));
     $this->setShortDateFormat($request->cookie('settings_short_date_format'));
     $this->setLongTimeFormat($request->cookie('settings_long_time_format'));
     $this->setShortTimeFormat($request->cookie('settings_short_time_format'));
     return $request->hasCookie('settings_locale');
 }
Example #16
0
 /**
  * Determine if a cookie is set on the request.
  *
  * @param string $key
  * @return bool 
  * @static 
  */
 public static function hasCookie($key)
 {
     return \Illuminate\Http\Request::hasCookie($key);
 }
 /**
  * Show the ticket purchase page
  * @param  string $slug The slug name of the event
  * @return view         Confirmation view
  */
 public function show(Request $request, $slug)
 {
     // Grab data from front end
     $data = \Input::get();
     // Iniciate apiHelper
     $api = new ApiHelper();
     if (!empty($data)) {
         $inventoryUrl = 'tickets/inventory';
         if (\Auth::check()) {
             $inventoryUrl .= '?auth_user_id=' . \Auth::user()->id;
         }
         // Pull data for the ticket
         $checkInventory = $api->store($inventoryUrl, $data);
     }
     // If inventory check fails
     if (isset($checkInventory) && $checkInventory['success'] !== true) {
         // Redirect back with fail message
         return Redirect::back()->with('fail_message', $checkInventory['error']);
     }
     $eventUrl = 'events/' . $slug . '?with[]=photos&with[]=ticketsInventory&with[]=nextEvent';
     if (\Auth::check()) {
         $eventUrl .= '&auth_user_id=' . \Auth::user()->id;
     }
     // Pull events with photos and ticketsInventory
     $events = $api->index($eventUrl);
     if (!isset($events['data']['event'])) {
         abort('404');
     }
     // Define Events
     $events = $events['data']['event'];
     // Set tickets
     $tickets = $events['ticketsInventory'];
     // Indexes and iterates through ticket inventory
     foreach ($events['ticketsInventory'] as $index => $ticketType) {
         $tickets = $events['ticketsInventory'];
         // If reservation is true, removes reservations and reorders array
         if ($ticketType['isReservation'] === true) {
             unset($events['ticketsInventory'][$index]);
             $tickets = array_values($events['ticketsInventory']);
         }
     }
     if (\Session::has('fail_message')) {
         $cost = \Session::get('cost');
         $many = \Session::get('many');
         $checkInventory = \Session::get('checkInventory');
     } else {
         // Set the initial cost to null
         $cost = null;
         $many[] = 0;
     }
     // Initiate purchased tickets
     $purchased = null;
     $purchasedId = [];
     $qty = [];
     // If qty is set
     if (isset($data['qty'])) {
         // For each qty count $n
         for ($n = 0; $n < count($data['qty']); $n++) {
             // If tickets has a selected value over or equal to 1 print its details
             if ($data['qty'][$n] >= 1) {
                 $purchased[] = ['name' => $tickets[$n]['name'], 'qty' => $data['qty'][$n]];
                 // Multiply the amount to the qty purchased
                 $total = $data['qty'][$n] * $tickets[$n]['amount'];
                 // Add the amount of Tickets purchased
                 $many[] = $data['qty'][$n];
                 $qty[] = $data['qty'][$n];
                 $purchasedId[] = $data['id'][$n];
                 // Pass the total to cost
                 $cost[] = $total;
             }
         }
         // If cost is not empty
         if ($cost !== null) {
             $cost = array_sum($cost);
         }
     }
     if ($many !== null) {
         $many = array_sum($many);
     }
     $response = new Response();
     $response->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
     $stateList = ['SS' => "Select State", 'AL' => "Alabama", 'AK' => "Alaska", 'AZ' => "Arizona", 'AR' => "Arkansas", 'CA' => "California", 'CO' => "Colorado", 'CT' => "Connecticut", 'DE' => "Delaware", 'DC' => "District Of Columbia", 'FL' => "Florida", 'GA' => "Georgia", 'HI' => "Hawaii", 'ID' => "Idaho", 'IL' => "Illinois", 'IN' => "Indiana", 'IA' => "Iowa", 'KS' => "Kansas", 'KY' => "Kentucky", 'LA' => "Louisiana", 'ME' => "Maine", 'MD' => "Maryland", 'MA' => "Massachusetts", 'MI' => "Michigan", 'MN' => "Minnesota", 'MS' => "Mississippi", 'MO' => "Missouri", 'MT' => "Montana", 'NE' => "Nebraska", 'NV' => "Nevada", 'NH' => "New Hampshire", 'NJ' => "New Jersey", 'NM' => "New Mexico", 'NY' => "New York", 'NC' => "North Carolina", 'ND' => "North Dakota", 'OH' => "Ohio", 'OK' => "Oklahoma", 'OR' => "Oregon", 'PA' => "Pennsylvania", 'RI' => "Rhode Island", 'SC' => "South Carolina", 'SD' => "South Dakota", 'TN' => "Tennessee", 'TX' => "Texas", 'UT' => "Utah", 'VT' => "Vermont", 'VA' => "Virginia", 'WA' => "Washington", 'WV' => "West Virginia", 'WI' => "Wisconsin", 'WY' => "Wyoming"];
     // Set eventTimeId
     $eventTimeId = isset($data['eventTimeId']) ? $data['eventTimeId'] : null;
     // Set default photo for carousel include view
     $defaultPhoto = isset($events['featuredPhoto']) ? $events['featuredPhoto'] : ['title' => null, 'url' => null];
     $updateErrors = \Session::get('updateErrors');
     if ($request->hasCookie('purchaseCookieData')) {
         $fromCookie = unserialize($request->cookie()['purchaseCookieData']);
         $purchased = $fromCookie['purchased'];
         $cost = $fromCookie['cost'];
         $eventTimeId = $fromCookie['eventTimeId'];
         $qty = $fromCookie['qty'];
         $many = $fromCookie['many'];
         $purchasedId = $fromCookie['purchasedId'];
         $defaultPhoto = $fromCookie['defaultPhoto'];
         return response()->view('events.tickets', ['events' => $events, 'updateErrors' => $updateErrors, 'stateList' => $stateList, 'purchased' => $purchased, 'cost' => $cost, 'eventTimeId' => $eventTimeId, 'qty' => $qty, 'many' => $many, 'purchasedId' => $purchasedId, 'defaultPhoto' => $defaultPhoto]);
     } else {
         $responseData = ['purchased' => $purchased, 'cost' => $cost, 'eventTimeId' => $eventTimeId, 'qty' => $qty, 'many' => $many, 'purchasedId' => $purchasedId, 'defaultPhoto' => $defaultPhoto];
         $cookieData = cookie('purchaseCookieData', serialize($responseData), 5);
         return response()->view('events.tickets', ['events' => $events, 'stateList' => $stateList, 'purchased' => $purchased, 'cost' => $cost, 'eventTimeId' => $eventTimeId, 'qty' => $qty, 'many' => $many, 'purchasedId' => $purchasedId, 'defaultPhoto' => $defaultPhoto])->withCookie($cookieData);
     }
 }