Laravel多Aiuth多表集会议,直到用户注销 [英] Laravel Multi-Aiuth with multiple table session set till user logout
问题描述
我已经实现多AUTH在laravel-4.2与多个表,以便相应地我登录查看职位3个值,第一个是用户名,第二个是密码,三是从下拉列表中值是mathches相同的值,验证::&LT ; 3值>() - >尝试,这有助于我与要求表登录,然后想,如果第3值为null,则验证用户::() - >尝试来使用。
多AUTH我使用'olliereadPAKAGE
验证执行code是
I have implemented multi-auth in laravel-4.2 with multiple tables So accordingly my login view posts 3 values,1st is username,2nd is password and 3rd is a value from dropdown which is mathches the same value as Auth::<3rd Value>()->attempt,Which helps me to log in with requested table,And suppose if 3rd value is null then Auth::user()->attempt come in use. for multi auth I am using 'ollieread' pakage Auth Implementation code is
auth.php:
<?php
return array(
'multi' => array(
'BSc' => array(
'driver' => 'database',
'table' => 'bsc',
'model' => 'BSc'
),
'user' => array(
'driver' => 'eloquent',
'model' => 'User',
'table' => 'users'
)
),
'reminder' => array(
'email' => 'emails.auth.reminder',
'table' => 'password_reminders',
'expire' => 60,
),
);
在过滤器编辑:
Route::filter('students', function()
{
if (Auth::BSc()->guest())
{
if (Request::ajax())
{
return Response::make('Unauthorized', 401);
}
else
{
return Redirect::guest('/'); }
}
});
Route::filter('auth.basic', function()
{
if (Auth::user()->guest())
{
if (Request::ajax())
{
return Response::make('Unauthorized', 401);
}
else
{
return Redirect::guest('/'); }
}
});
UserController的@ postLogin:
UserController@postLogin:
public function postLogin()
{
$username = Input::get('username');
$model_name = Input::get('course');
$password = Input::get('password'),
$credentials = array(
'username' => $username,
'password' => $password,
);
//class exists(Model exist?)
if(!(is_null($model_name))){
if(class_exists($model_name)){
if(Auth::$model_name()->attempt($credentials))
{
return Redirect::to('desk')->with('stream',$model_name);
}
else
{
echo "Invalid UserName";
}
}else{
echo "No model is created for ".$model_name;
}
}else{
if(Auth::user()->attempt($credentials)){
return Redirect::intended('desktop')->with('stream',"Test");
}
else{
echo "Username is invalid";
}
}
在postLogin功能,在重定向路由服务台我传递变量$ MODEL_NAME在会话,这将帮助我知道该用户是存储在哪个表,
In postLogin function,at the redirecting to route "desk" I am passing variable $model_name to store in session which will help me know the user is from which table,
有关第一次重定向到/台登陆$ MODEL_NAME后显示正确传递价值,我通过检索在办公桌鉴于值,
For first time on redirecting to /desk after login the $model_name shows the correct passed value,I retrieving the value in desk view by,
<?php
$stream = Session::get('stream');
var_dump($stream);
?>
现在它转储与重定向传递正确的值,但正如我刷新页面的价值变为零。
Now it dumps the correct value passed with redirect But as i refresh the page the value turns to null.
如果我能能设定这个数值,直到用户注销,这将有助于与$流值注销。
If I could able set this value till the user logs out,It would help to log out with that $stream value.
也可用于
Auth::$stream()->username
那么,怎样才能设置会话::得到('流')值不变,直到用户注销?
希望我正确解释。
So How can set the session::get('stream') value constant till the user logs out? Hope I have explained correctly.
推荐答案
为了保存您可以使用laravel 4届门面会话值如下:
In order to store the session value you may use the Session facade of laravel 4 as follows:
//class exists(Model exist?)
if(!(is_null($model_name))){
if(class_exists($model_name)){
if(Auth::$model_name()->attempt($credentials))
{
Session::put('stream', $model_name);
return Redirect::to('desk');
}
else
{
echo "Invalid UserName";
}
}else{
echo "No model is created for ".$model_name;
}
}else{
if(Auth::user()->attempt($credentials)){
return Redirect::intended('desktop')->with('stream',"Test");
}
else{
echo "Username is invalid";
}
}
该值与名称(键)'流'你用会话::忘记('键')或Session ::平齐()(它可以在你登出功能使用)会话,直到你留在那里。您可能还喜欢去通过此页面。
我希望这能解决你的问题。请让我知道,如果它没有。
I hope this solves your problem. Please let me know if it didn't.
这篇关于Laravel多Aiuth多表集会议,直到用户注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!