Reputation: 31
I'm using Laravel to build an application, which needs user authentication. As such, I used the Auth library to make it. However, when I tested it, when I tried to sign out it first said "Whoops, looks like something went wrong!" and only when I refreshed did it work.
This is the dashboard page
@extends('layouts.default')
@section('navbar-content')
<ul class="nav navbar-nav">
<li class="active"><a href="{{ URL::route('Home') }}">Home</a></li>
<li><a href="{{ URL::route('GetSignOut') }}">Sign Out</a></li>
</ul>
<p class="navbar-text navbar-right">Signed in as <a href="" class="navbar-link">{{Auth::user()->name }}</a></p>
@stop
@section('content')
<div class="col-md-3">
</div>
<div class="col-md-6">
</div>
<div class="col-md-3">
</div>
@stop
Routes:
<?php
Route::get('/', array ('as' => 'Home', 'uses' => 'HomeController@goHome'));
Route::get('/sign-in', array ('as' => 'GetSignIn', 'uses' => 'AuthController@getSignIn'));
Route::post('/sign-in', array('as' => 'PostSignIn', 'uses' => 'AuthController@postSignIn'));
Route::get('/sign-out', array('as' => 'GetSignOut', 'uses' => 'AuthController@getSignOut'));
Authentication Controller:
<?php
class AuthController extends BaseController {
public function getSignIn() {
return View::make('sign-in');
}
public function postSignIn() {
$validator = Validator::make(Input::all(), array(
'email' => 'required|max:255',
'password' => 'required'
));
if ($validator->fails()) {
return Redirect::route('GetSignIn')->withErrors($validator);
}
$auth = Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password')
), false);
if (!$auth) {
return Redirect::route('GetSignIn')->withErrors(array ('Invalid credentials'));
}
return Redirect::route('Home');
}
public function getSignOut() {
Auth::logout();
return Redirect::route('Home');
}
}
Upvotes: 0
Views: 1106
Reputation: 313
Take a look at this upgrade guide.
You need to add a new, nullable
remember_token
column of VARCHAR(100)
to your users
table.
Upvotes: 4