Working on removing authentication boilerplate.
This commit is contained in:
@@ -1,103 +1,21 @@
|
||||
<?php namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\User;
|
||||
use App\Http\Requests;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
||||
|
||||
class AuthController extends Controller {
|
||||
|
||||
/**
|
||||
* The Guard implementation.
|
||||
*
|
||||
* @var Guard
|
||||
*/
|
||||
protected $auth;
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 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?
|
||||
|
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a new authentication controller instance.
|
||||
*
|
||||
* @param Guard $auth
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
|
||||
$this->middleware('guest', ['except' => 'getLogout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application registration form.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function getRegister()
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a registration request for the application.
|
||||
*
|
||||
* @param RegisterRequest $request
|
||||
* @return Response
|
||||
*/
|
||||
public function postRegister(Requests\Auth\RegisterRequest $request)
|
||||
{
|
||||
$user = User::forceCreate([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => bcrypt($request->password),
|
||||
]);
|
||||
|
||||
$this->auth->login($user);
|
||||
|
||||
return redirect('/home');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application login form.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function getLogin()
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a login request to the application.
|
||||
*
|
||||
* @param LoginRequest $request
|
||||
* @return Response
|
||||
*/
|
||||
public function postLogin(Requests\Auth\LoginRequest $request)
|
||||
{
|
||||
$credentials = $request->only('email', 'password');
|
||||
|
||||
if ($this->auth->attempt($credentials, $request->has('remember')))
|
||||
{
|
||||
return redirect('/home');
|
||||
}
|
||||
|
||||
return redirect('/auth/login')
|
||||
->withInput($request->only('email'))
|
||||
->withErrors([
|
||||
'email' => 'These credentials do not match our records.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the user out of the application.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function getLogout()
|
||||
{
|
||||
$this->auth->logout();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
use AuthenticatesAndRegistersUsers;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user