credentials
単一のusers
テーブルを使用している同じブラウザウィンドウで、ユーザーが異なる方法でログインできるようにしたい。テーブルが異なっていれば、私は確かにそれを行いますguards
が、問題は、単一のテーブルを介してユーザーログインを管理する必要があることです。
新しいタブで他のアカウントでログインすると最初のアカウントがログアウトするので、同じブラウザウィンドウで複数のセッションを管理する方法を教えてください。
前もって感謝します。
私がやりたかったのはmultiple session
、ユーザーが同じブラウザウィンドウ内のさまざまなタブで他の電子メールIDを使用してログインできるように維持することでした。ここでは、それをどのように管理できるか、そしてどのように管理しているかについて説明Gmail
します。
user
、彼の他のアカウントでログインするか、アカウントを切り替えたいです。したがって、url
アカウントを切り替えたいことを示す表記を追加することで、ログインページを表示できます。元のlogin
URLがhttp://www.examle.com/login
複数ログイン用の場合は、次のようなURLhttp://www.examle.com/u/1/login
を指定できます(u/
アカウントを切り替えたい回数だけ、パーツの後に番号を増やすことができます)。
config/sessions.php
、cookie
次のようにパーツを編集します<?php
$user_type = ( ( !empty(request()) && (int)request()->segment(2) ) > 0 ? '_'. request()->segment(2) : '');
return [
//.....rest of array
'cookie' => env(
'SESSION_COOKIE',
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'. $user_type //This user_type generate various session keys for your multiple login according to generated URL
),
];
次に、すべてのURLを変更してdynamic
、通常のroute(without '/u/number/url' part
)と/u/number/url
パーツの両方で実行できるようにする必要があります。
上部に次の変数を定義します web.php
/**
* Setting a variable to check if the user is logging in with first or multiple sessions
*/
$user_login = ( (int)request()->segment(2) > 0 ? 'u/'. request()->segment(2) : '' );
/**
* User attempting to login with other accounts
*/
Route::post($user_login. '/login', 'Auth\LoginController@login');
/**
* Get dashboard for filling the registeration forms
* Your entire app URL will now go like this, whether you can use it with user number or without it. It will go smoothly
*/
Route::get($user_login. '/dashboard', ['as' => 'dashboard', 'uses' => 'FormController@getDashboard']);
/**
* User attempting to login with other accounts
*/
Route::post($user_login. '/logout', 'Auth\LoginController@logout');
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加