/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!Cookie::has('d_i')) { Cookie::queue(Cookie::forever('d_i', str_random(60))); } return $next($request); }
/** * Create a cookie that lasts "forever" (five years) * * @static * @param string $name * @param mixed $value * @param string $path * @param string $domain * @param bool $secure * @param bool $httpOnly * @return \Symfony\Component\HttpFoundation\Cookie */ public static function forever($name, $value, $path = NULL, $domain = NULL, $secure = FALSE, $httpOnly = TRUE) { // Serialize the value $value = @serialize($value); // Create the cookie return parent::forever($name, $value, $path, $domain, $secure, $httpOnly); }
public function store() { $preferences = Request::all(); $response = new Response('OK'); $response->withCookie(Cookie::forever(PreferencesVO::PREFERENCES_AMOUNT, $preferences['amount'], PreferencesVO::PREFERENCES_LIFESPAN))->withCookie(Cookie::forever(PreferencesVO::PREFERENCES_PERIOD, $preferences['period'], PreferencesVO::PREFERENCES_LIFESPAN))->withCookie(Cookie::forever(PreferencesVO::PREFERENCES_TAXCDB, $preferences['taxcdb'], PreferencesVO::PREFERENCES_LIFESPAN))->withCookie(Cookie::forever(PreferencesVO::PREFERENCES_TAXLCI, $preferences['taxlci'], PreferencesVO::PREFERENCES_LIFESPAN)); return $response; }
/** * @param array $content * @return mixed */ public function createCookie(array $content) { if (!isset($this->info[CookieManager::COOKIE_TIME]) || $this->info[CookieManager::COOKIE_TIME] == null) { $cookie = Cookie::forever($this->info[CookieManager::COOKIE_NAME], json_encode($content)); } else { $cookie = Cookie::make($this->info[CookieManager::COOKIE_NAME], json_encode($content), $this->info[CookieManager::COOKIE_TIME]); } return $cookie; }
private static function newCookie($user) { $cv = str_random(32); $cookie = Cookie::forever('laravel-remember', $cv); $uc = new UserCookie(); $uc->user_id = $user->id; $uc->cookie = $cv; $uc->save(); return $cookie; }
/** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ protected function confirmAccount() { $page = "Verifieer E-mail"; if (Session::has('user') && Cookie::get('user') === null) { $user = Session::get('user'); $cookie = Cookie::forever('user', $user); return response()->view('dividers.verification', compact('page', 'user'))->withCookie($cookie); } if (Cookie::get('user') !== null) { $user = Cookie::get('user'); $userIs = User::where('email', $user->email)->first(); if ($userIs !== null && $userIs->verified) { return Redirect::to('login')->withCookie(Cookie::forget('user')); } return view('dividers.verification', compact('page', 'user')); } }
/** * @param LoginRequest $request * @param $user * @param $page * @return $this|\Illuminate\Http\RedirectResponse */ private function signIn(LoginRequest $request, $user, $page) { if ($user !== null) { try { // verify user $user->isVerified(); // validate $user->validate($this->getCredentials($request)); // sign in user Auth::login($user); // Flash success message alert()->success('Welkom ' . $user->firstname . ' ' . $user->lastname . '!')->autoclose(2500); // Log login statistics $user->updateLastLogin(); // Redirect where the user intended to go return redirect()->intended('/dashboard'); if ($user->is('admin')) { return redirect()->intended('/dashboard'); } if ($user->is('user')) { return redirect()->intended('/dashboard'); } } catch (UserNotVerified $e) { // check to redirect with dashboard with or without cookie if (Cookie::get('user') !== null) { return redirect()->to('register/confirm')->with('user', $user); } else { return response()->view('dividers.verification', compact('page', 'user'))->withCookie(Cookie::forever('user', $user)); } } catch (ValidationFailed $e) { // flash failure alert()->error('Verkeerd wachtwoord of E-mail!')->autoclose(2500); // redirect back return redirect()->back(); } } return redirect()->back()->withErrors($request); // Redirect back with errors }
public function rememberLogin(Person $person) { $value = $person->getId() . '-' . $person->getRememberToken(); Cookie::queue(Cookie::forever($this->getAutoLoginCookie(), $value)); }
public function createComment(Request $request, $id) { $this->validate($request, ['comment' => 'required|max:1000', 'username' => 'required|min:2|max:50', 'email' => 'required|email', 'url' => 'url']); $article = Articles::findOrFail($id); $comment = new ArticlesComments($request->all()); $article->comments()->save($comment); /** * I think need to save username, email and url to cookies */ Cookie::queue(Cookie::forever('username', $request->input('username'))); Cookie::queue(Cookie::forever('email', $request->input('email'))); Cookie::queue(Cookie::forever('url', $request->input('url'))); return view('articles.comments', compact('article')); }
public function vote(Request $request) { $ip = $request->getClientIp(); $cookie = md5($request->input('parent_id')); $voteCookie = Cookie::forever('vote', $cookie); if (DB::table('votes')->insert(['poll_id' => $request->input('id'), 'parent_id' => $request->input('parent_id'), 'ip' => ip2long($ip), 'cookie' => $cookie, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()])) { return response('success')->withCookie($voteCookie); } else { return 'error'; } }