本文整理汇总了PHP中Illuminate\Http\Request::session方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::session方法的具体用法?PHP Request::session怎么用?PHP Request::session使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listing
/**
* Shows a listing of modmails based on the given criteria
*/
public function listing(Request $request)
{
$input = [];
if ($request->session()->has('input') && count($request->all()) < 2) {
$input = $request->session()->get('input');
} else {
$input = $request->all();
$request->session()->put('input', $input);
}
$input['startdate'] = strtotime($input['startdate']);
$input['enddate'] = strtotime($input['enddate']) + 60 * 60 * 24;
$input['order'] = intval($input['order']);
$db = DB::connection('mongodb');
$modmail = $db->collection('modmail');
if ($input['subject'] != '') {
$modmail->orWhere('subject', 'like', '%' . $input['subject'] . '%')->orWhere('replies.subject', 'like', '%' . $input['subject'] . '%');
}
if ($input['body'] != '') {
$modmail->orWhere('body', 'like', '%' . $input['body'] . '%')->orWhere('replies.body', 'like', '%' . $input['body'] . '%');
}
if ($input['author'] != '') {
$modmail->orWhere('author', $input['author'])->orWhere('replies.author', $input['author']);
}
$results = $modmail->where('created_at', '>', $input['startdate'])->where('created_at', '<', $input['enddate'])->orderBy('created_at', $input['order'] == 1 ? 'asc' : 'desc')->take(2000)->paginate(50);
$filters = ['start' => number_format($results->perPage() * ($results->currentPage() - 1) + 1), 'end' => number_format($results->perPage() * $results->currentPage()), 'total' => number_format($results->total()), 'from' => strftime('%d %B %Y', $input['startdate']), 'to' => strftime('%d %B %Y', $input['enddate']), 'author' => $input['author'] != '' ? $input['author'] : 'anyone', 'subject' => $input['subject'] != '' ? $input['subject'] : 'anything', 'body' => $input['body'] != '' ? $input['body'] : 'anything'];
$data = ['results' => $results, 'filters' => $filters];
return view('log.modmail.listing', $data);
}
示例2: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param Closure $next
* @param string|null $guard
*
* @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*
* @fires JsonWebTokenExpired
*/
public function handle($request, Closure $next, $guard = null)
{
$autheticated_user = Auth::guard($guard)->user();
$has_valid_token = false;
// Is the user has used "remember me" the token may not be in their session when they return
if ($request->session()->has('jwt')) {
$token = $request->session()->get('jwt');
try {
$token_user = $this->auth->authenticate($token);
if ($token_user->id !== $autheticated_user->id) {
throw new JWTException('Token does not belong to the authenticated user');
}
$has_valid_token = true;
} catch (TokenExpiredException $e) {
$has_valid_token = false;
} catch (JWTException $e) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('login');
}
}
}
// If there is no valid token, generate one
if (!$has_valid_token) {
event(new JsonWebTokenExpired($autheticated_user));
}
return $next($request);
}
示例3: getTutorSearch
public function getTutorSearch(Request $request)
{
$defaultsubjects = DefaultSubject::OrderBy('subject')->get();
$sort = 'N';
if ($request->has('tutorsearch')) {
if ($request->session()->has('tutorsearch')) {
$request->session()->forget('tutorsearch');
}
$request->session()->put('tutorsearch', $request->input('tutorsearch'));
$input = $request->input('tutorsearch');
if ($request->session()->has('tutorcount')) {
$request->session()->forget('tutorcount');
}
$t = User::with('tutorinfo')->with('subjects')->select('users.*')->where(['type' => 'tutor'])->leftJoin('subjects', function ($join) {
$join->on('subjects.userid', '=', 'users.id');
})->whereIn('subject', $input)->orderBy('subjects.subject', 'ASC')->groupBy('users.id')->get();
$counttutor = count($t);
$request->session()->put('tutorcount', $counttutor);
} else {
$counttutor = $request->session()->get('tutorcount');
$input = $request->session()->get('tutorsearch');
}
$tutors = User::with('tutorinfo')->with('subjects')->select('users.*')->where(['type' => 'tutor'])->leftJoin('subjects', function ($join) {
$join->on('subjects.userid', '=', 'users.id');
})->whereIn('subject', $input)->groupBy('users.id')->paginate(10);
$tutors->setpath(URL::route('tutorsearch'));
return view('project.main.findtutor')->with('title', 'Find Private Tutor | ' . $this->sitename)->with('tutors', $tutors)->with('tutorcount', $counttutor)->with('sort', $sort)->withsubjects($input)->with('defaultsubjects', $defaultsubjects);
}
示例4: getLogout
public function getLogout(Request $request)
{
$request->session()->forget('email');
$request->session()->forget('password');
$request->session()->forget('user');
return redirect()->to('login');
}
示例5: reset
public function reset(Request $request)
{
Auth::logout();
$request->session()->flush();
$request->session()->regenerate();
return redirect('/');
}
示例6: logout
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
return redirect('/login');
}
示例7: handle
/**
* Run the request filter.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$request->session()->has('sift_session_id')) {
$request->session()->put('sift_session_id', Str::random(24));
}
return $next($request);
}
示例8: uploadImage
public function uploadImage(Request $request)
{
$file = Input::file('image1');
$rules = array('image1' => 'required|image');
$result = array('success' => 0);
$validator = Validator::make(array('image1' => $file), $rules);
if (!$validator->fails() && $file->isValid()) {
if ($request->session()->has('image')) {
@unlink($request->session()->get('image'));
}
$destpath = 'uploads';
$origname = $file->getClientOriginalName();
$ext = $file->getClientOriginalExtension();
$id = 1;
while (file_exists($destpath . '/' . $id . '-' . $origname)) {
$id++;
}
$filename = $id . '-' . $origname;
$url = $destpath . '/' . $filename;
$thumb_url = $destpath . '/thumbs/' . $filename;
$file->move($destpath, $filename);
$thumb = Image::make($url)->resize(222, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save($thumb_url);
$request->session()->put('image', $url);
$result = array('success' => 1, 'url' => $url, 'thumb_url' => $thumb_url);
}
return response()->json($result);
}
示例9: getLogout
/**
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function getLogout(Request $request)
{
$request->session()->forget('user');
$request->session()->forget('email');
$request->session()->forget('password');
return redirect()->to('frontend/login/login')->withSuccess('Logged out successfully');
}
示例10: enable
/**
* Permet de ré-activer un compte
*
* @param Request $request
* @param int $user_id Identifiant utilisateur
* @param string $credentials_hash Hash des credentials de l'utilisateur
* @param string $deleted_at_hash Hash de la date de la désactivation du compte
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function enable(Request $request, $user_id, $credentials_hash, $deleted_at_hash)
{
// Oui, c'est sale, mais c'est pour éviter de dire à un utilisateur malveillant que le compte n'existe pas, existe,
// que c'est le hash des credentials qui est mauvais, ou que c'est le hash du deleted_at qui est mauvais
// Au final, s'il y a une étape qui a merdée, on lui dit juste que la réactivation était impossible. :-)
$error = false;
// On n'oublie pas le withTrashed(), sinon ça ne renvoie rien
$user = User::withTrashed()->find($user_id);
if ($user === null) {
$error = true;
}
if (!$error && ($credentials_hash !== $user->getHashedCredentials() || $deleted_at_hash !== $user->getHashedDeletedAt())) {
$error = true;
}
if ($error) {
$request->session()->flash('message', 'danger|La réactivation de ce compte est impossible.');
} else {
// Réactivation du compte
$user->deleted_at = null;
$user->update();
Auth::loginUsingId($user->id);
$request->session()->flash('message', 'success|Votre compte a été réactivé avec succès !');
}
return redirect(route('index'));
}
示例11: logout
public function logout(Request $request)
{
if ($request->session()->has('ApiDocsPassword')) {
$request->session()->forget('ApiDocsPassword');
}
return redirect('apidocs/login');
}
示例12: getLogout
/**
* Log the user out of the application.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*/
public function getLogout(Request $request)
{
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
return redirect()->route('home')->with(['success' => 'You are logged out. Come again!']);
}
示例13: anyIndex
/**
* /login
* Authenticate the user via Google OAuth then redirect to homepage.
*
* @param Request $request
* @param Google_Client $googleClient
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
*/
public function anyIndex(Request $request, Google_Client $googleClient)
{
if ($code = $request->input('code')) {
if ($request->session()->get('state') != $request->input('state')) {
App::abort(400, 'The session state did not match.');
}
$googleClient->authenticate($code);
// Now get the user and log them in to the app
$oauth2 = new Google_Service_Oauth2($googleClient);
$userInfo = $oauth2->userinfo->get();
if ($user = User::where('google_user_id', $userInfo->id)->first()) {
// User is already in DB.
} else {
// Create a new user.
$user = new User(['google_user_id' => $userInfo->id]);
}
$user->setAccessToken($googleClient->getAccessToken(), $googleClient->getRefreshToken());
$user->name = $userInfo->name;
$user->save();
Auth::login($user);
return redirect()->secure('/');
}
$state = (string) mt_rand();
$googleClient->setState($state);
$request->session()->flash('state', $state);
$googleClient->setApprovalPrompt('force');
$authUrl = $googleClient->createAuthUrl();
return redirect($authUrl);
}
示例14: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
// https://developers.google.com/identity/protocols/OAuth2WebServer
$this->client->setAccessType('offline');
// To get a refresh token, per <http://stackoverflow.com/a/31237203/489916>
$this->client->setApprovalPrompt('force');
if (\Storage::disk('local')->exists('google_access_token.json')) {
$token = \Storage::disk('local')->get('google_access_token.json');
$this->client->setAccessToken($token);
}
if ($request->path() == 'oauth2callback' && $request->has('code')) {
if ($request->session()->get('google_oauth_state') !== $request->get('state')) {
abort(500, 'The session state did not match.');
}
$this->client->authenticate($request->get('code'));
\Storage::disk('local')->put('google_access_token.json', $this->client->getAccessToken());
return redirect('/');
} elseif (is_null($this->client->getAccessToken())) {
// If the user hasn't authorized the app, initiate the OAuth flow
$state = strval(mt_rand());
$this->client->setState($state);
$request->session()->put('google_oauth_state', $state);
$authUrl = $this->client->createAuthUrl();
return response()->view('google.authorize', ['authUrl' => $authUrl]);
}
return $next($request);
}
示例15: postFinishTaxApply
/**
* 完成税务申报
* @param Request $request
* @return mixed
* @author AndyLee <root@lostman.org>
*/
public function postFinishTaxApply(Request $request)
{
$input = $request->only('type', 'flag');
$map = ['user_id' => $request->session()->get('company_id'), 'company_id' => $request->session()->get('customer_id')];
/*
* 国税部分
*/
if ($input['type'] == 'guoshui') {
$map['guoshui_status'] = 0;
$tax = Tax::where($map)->first();
if (!empty($tax)) {
$tax->guoshui_status = 1;
$tax->save();
return \Response::json(['message' => '国税申报完成', 'state' => 'success']);
}
}
if ($input['type'] == 'dishui') {
$map['dishui_status'] = 0;
$tax = Tax::where($map)->first();
if (!empty($tax)) {
$tax->dishui_status = 1;
$tax->save();
return \Response::json(['message' => '地税申报完成', 'state' => 'success']);
}
}
}