本文整理汇总了PHP中Illuminate\Http\Request::hasCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::hasCookie方法的具体用法?PHP Request::hasCookie怎么用?PHP Request::hasCookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::hasCookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getModel
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;
}
示例2: handle
/**
* 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);
}
示例3: handle
public function handle(Request $request, Closure $next)
{
if ($request->hasCookie('lang')) {
app()->setLocale($request->cookie('lang'));
}
return $next($request);
}
示例4: handle
/**
* 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);
}
示例5: getLocale
/**
* {@inheritdoc}
*/
public function getLocale()
{
if ($this->request->hasCookie('locale')) {
return $this->request->cookie('locale');
} else {
return $this->getConfigDefaultLocale();
}
}
示例6: findOrCreateTrackingCookieToken
/**
* @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;
}
示例7: index
/**
* 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');
}
示例8: handle
/**
* 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));
}
}
示例9: landing
/**
* 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');
}
示例10: handle
/**
* @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()));
}
}
示例11: handle
/**
* 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);
}
示例12: handle
/**
* 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));
}
示例13: handle
/**
* 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);
}
示例14: store
/**
* 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();
}
示例15: fromCookie
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');
}