Last active
August 29, 2015 14:25
-
-
Save aaronpk/604936d3e7ce7bf22fb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// When I try to sign in, I get TokenMismatchException | |
namespace App\Http\Controllers\Auth; | |
use App\User; | |
use Validator; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; | |
class AuthController extends Controller | |
{ | |
/* | |
|-------------------------------------------------------------------------- | |
| Registration & Login Controller | |
|-------------------------------------------------------------------------- | |
| | |
| This controller handles the registration of new users, as well as the | |
| authentication of existing users. By default, this controller uses | |
| a simple trait to add these behaviors. Why don't you explore it? | |
| | |
*/ | |
use AuthenticatesAndRegistersUsers; | |
/** | |
* Create a new authentication controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('session.start'); | |
$this->middleware('session.errors'); | |
$this->middleware('csrf'); | |
$this->middleware('guest', ['except' => 'getLogout']); | |
} | |
/** | |
* Get a validator for an incoming registration request. | |
* | |
* @param array $data | |
* @return \Illuminate\Contracts\Validation\Validator | |
*/ | |
protected function validator(array $data) | |
{ | |
return Validator::make($data, [ | |
'name' => 'required|max:255', | |
'email' => 'required|email|max:255|unique:users', | |
'password' => 'required|confirmed|min:6', | |
]); | |
} | |
/** | |
* Create a new user instance after a valid registration. | |
* | |
* @param array $data | |
* @return User | |
*/ | |
protected function create(array $data) | |
{ | |
return User::create([ | |
'name' => $data['name'], | |
'email' => $data['email'], | |
'password' => bcrypt($data['password']), | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This one works as expected | |
namespace App\Http\Controllers; | |
class HomeController extends Controller | |
{ | |
public function __construct() | |
{ | |
$this->middleware('session.start'); | |
$this->middleware('session.errors'); | |
$this->middleware('csrf'); | |
$this->middleware('auth'); | |
} | |
public function index() | |
{ | |
return view('home'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http; | |
use Illuminate\Foundation\Http\Kernel as HttpKernel; | |
class Kernel extends HttpKernel | |
{ | |
/** | |
* The application's global HTTP middleware stack. | |
* | |
* @var array | |
*/ | |
protected $middleware = [ | |
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, | |
\Illuminate\Cookie\Middleware\EncryptCookies::class, | |
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, | |
]; | |
/** | |
* The application's route middleware. | |
* | |
* @var array | |
*/ | |
protected $routeMiddleware = [ | |
'auth' => \App\Http\Middleware\Authenticate::class, | |
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, | |
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, | |
'csrf' => \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class, | |
'session.start' => \Illuminate\Session\Middleware\StartSession::class, | |
'session.errors' => \Illuminate\View\Middleware\ShareErrorsFromSession::class, | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('app') | |
@section('content') | |
<div class="container-fluid"> | |
<div class="row"> | |
<div class="col-md-8 col-md-offset-2"> | |
<div class="panel panel-default"> | |
<div class="panel-heading">Login</div> | |
<div class="panel-body"> | |
@if (isset($errors) && count($errors) > 0) | |
<div class="alert alert-danger"> | |
<strong>Whoops!</strong> There were some problems with your input.<br><br> | |
<ul> | |
@foreach ($errors->all() as $error) | |
<li>{{ $error }}</li> | |
@endforeach | |
</ul> | |
</div> | |
@endif | |
<form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/login') }}"> | |
<input type="hidden" name="_token" value="{{ csrf_token() }}"> | |
<div class="form-group"> | |
<label class="col-md-4 control-label">E-Mail Address</label> | |
<div class="col-md-6"> | |
<input type="email" class="form-control" name="email" value="{{ old('email') }}"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label class="col-md-4 control-label">Password</label> | |
<div class="col-md-6"> | |
<input type="password" class="form-control" name="password"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<div class="col-md-6 col-md-offset-4"> | |
<div class="checkbox"> | |
<label> | |
<input type="checkbox" name="remember"> Remember Me | |
</label> | |
</div> | |
</div> | |
</div> | |
<div class="form-group"> | |
<div class="col-md-6 col-md-offset-4"> | |
<button type="submit" class="btn btn-primary">Login</button> | |
<a class="btn btn-link" href="{{ url('/password/email') }}">Forgot Your Password?</a> | |
</div> | |
</div> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
@endsection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment