Pergunta

I recently built my first web application using laravel and overall it has been great. I have picked up the framework very easily except for this one issue. I am trying to use the framework's built in authentication. I am able to log in my users for a given request but I am trying to implement the remember me functionality by the Auth::attempt() method passing in true as the second parameter as per the documentation.Laravel Documentation

I have been trying this method for many hours without any luck. I have seen a video at this url (https://www.youtube.com/watch?v=hYUf6u_txhk#aid=P-a-d6RlOC8) which shows which cookie is set when a user is remembered in the application and this cookie is not being set in my browser when I try to remember my user. The cookie is not being set and my users are not being remembered. Here is my code.

if (Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password')), true))
        {
            $userid = DB::table('users')->where('email', '=', $userdata['email'])->pluck('id');

            Auth::login(Auth::user());

            if (Auth::check())
            {
                echo "LOGGGEED IN WOOOOOOO";
            }
            else {
                echo "user not logged in";
            }

            return Redirect::to('/dashboard/' . $userid);
        }

Before the redirect happens here is the page I see enter image description here

Here is the controller that handles the redirect.

class DashboardController extends BaseController
{
public function showDashboard($userid)
{
    if (Auth::viaRemember())
    {
        echo "WOOOOOOOOOOOOOOOO";

    }
    else {
        echo 'booooooo';
    }
    if (Auth::check())
    {
        echo 'YAY LOGGED IN';
    }
    else {
        echo 'BOO AGAIN';
    }
    $user = User::where('id', '=', $userid)->first();
    $subscriptions = $user->subscriptions;
    $orders = $user->orders;

    return View::make('dashboard', compact('user', 'subscriptions', 'orders'));
}
}

But when the redirect happens and /dashboard/{userid} is loaded you can see in the top left hand corner that my echo statements show the user is not being remembered!
enter image description here

I am so frustrated at this point since this is the last step I need to finish my application and I am embarrassed that the laravel documentation says "Laravel aims to make the implementation simple". I have the entire rest of my application working EXCEPT for this part so I would appreciate any and all help with this issue! If you need anymore information please feel free to ask me.Dashboard page

Foi útil?

Solução

SOLUTION:

In app/config/session.php in the array my 'driver' key had a value of 'file'. After switching this to 'cookie' everything worked as expected.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top