dongtuan1594 2016-07-18 10:25
浏览 55

Laravel 5.2 Auth ::重定向后尝试丢失值

I have a problem logging in in my laravel app. The user logged in, but after the redirect lose all the authenticate information. I saw that there is a lots of questions about that but i didn't saw one tha answer what I need.

I'm working on Laravel 5.2.39 so the web middleware is added automaticaly.

This is my routes.php

Route::group(['prefix' => 'dspanel'], function () {
//LOGIN DE DSNET
Route::get('/', ['middleware'=>'auth', function ()    {
    return view('admin.index');
}]);

//DIRECCIONES DEL ADMIN
Route::get('login', function ()    {
    return view('admin.login');
});

Route::post('validar', 'AdminController@login');

});

This is my AdminController::login

public function login(Request $request)
{
    $user = array(
    'email' => $request->input('email'),
    'password' => $request->input('password')
    );

    if($request->input('remember'))
    {
        $remember = true;
        Config::set('session.expire_on_close', true);           
    }
    else
    {
        $remember = false;
        Config::set('session.expire_on_close', false);
    }

    if (Auth::attempt($user, $remember)) 
    {
        echo "<b>Auth::attempt: </b>";
        var_dump(Auth::attempt($user, $remember));
        echo "<br>-------<br>";
        echo "<b>Auth::check: </b>";
        var_dump(Auth::check($user, $remember));
        echo "<br>-------<br>";
        echo "<b>Auth::user: </b>";
        var_dump(Auth::user($user, $remember));
        echo "<br>-------<br>";
        exit();
        /*$request->session()->put('usrNombre', Auth::user()->nombre);
        $request->session()->put('usrEmail', Auth::user()->email);
        $request->session()->put('usrTelefono', Auth::user()->telefono);
        $request->session()->put('usrId', Auth::user()->usuario_id);*/
        return Redirect::to('/dspanel');
    } else {
        return Redirect::to('/dspanel/login')->with('error', 1001);
    }
}

I Put few prints to see what happend, and in this point, the user is autenticate right, this is what the prints and var_dump give me back:

Auth::attempt: bool(true)
------- Auth::check: bool(true)
------- Auth::user: object(App\Admin)#180 (25) { ["table":protected]=> string(10) "ad_usuario" ["primarykey":protected]=> string(10) "usuario_id" ["timestamps"]=> bool(false) ["fillable":protected]=> array(4) { [0]=> string(6) "nombre" [1]=> string(5) "email" [2]=> string(8) "telefono" [3]=> string(8) "password" } ["hidden":protected]=> array(2) { [0]=> string(8) "password" [1]=> string(14) "remember_token" } ["connection":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["attributes":protected]=> array(11) { ["usuario_id"]=> string(1) "6" ["nombre"]=> string(11) "David Sujoy" ["apellido"]=> string(0) "" ["username"]=> string(0) "" ["password"]=> string(60) "$2y$10$0AO7KYKD3Eq7YkLuuXpsVOWi5i47Jqptlb5.yI/qRHF8SrM9Il.Dm" ["email"]=> string(19) "dsujoy@dsnet.com.ar" ["telefono"]=> string(16) "+972 52 717 9482" ["estado"]=> string(1) "0" ["categoria_id"]=> string(1) "0" ["grupo_id"]=> string(1) "1" ["remember_token"]=> string(0) "" } ["original":protected]=> array(11) { ["usuario_id"]=> string(1) "6" ["nombre"]=> string(11) "David Sujoy" ["apellido"]=> string(0) "" ["username"]=> string(0) "" ["password"]=> string(60) "$2y$10$0AO7KYKD3Eq7YkLuuXpsVOWi5i47Jqptlb5.yI/qRHF8SrM9Il.Dm" ["email"]=> string(19) "dsujoy@dsnet.com.ar" ["telefono"]=> string(16) "+972 52 717 9482" ["estado"]=> string(1) "0" ["categoria_id"]=> string(1) "0" ["grupo_id"]=> string(1) "1" ["remember_token"]=> string(0) "" } ["relations":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["casts":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["morphClass":protected]=> NULL ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) }
-------

And after that, without the exit() try to make the return redirect::to(/dspanel) the root of the administrator. I this route is the auth middleware that send me back to the login screen. and if I check here The Auth::check() it's false and Auth::user() is empty.

I check a lot of issues about that, but i cannot fixed. I'm new y laravel 5.2 i was using always the 4.2 version.

Best regards to all.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 关于#python#的问题:自动化测试