108 lines
1.8 KiB
PHP
108 lines
1.8 KiB
PHP
<?php namespace App\Http\Controllers\Auth;
|
|
|
|
use Illuminate\Contracts\Auth\Guard;
|
|
|
|
use App\Http\Requests\Auth\LoginRequest;
|
|
use App\Http\Requests\Auth\RegisterRequest;
|
|
|
|
/**
|
|
* @Middleware("csrf")
|
|
* @Middleware("guest", except={"logout"})
|
|
*/
|
|
class AuthController {
|
|
|
|
/**
|
|
* The Guard implementation.
|
|
*
|
|
* @var Guard
|
|
*/
|
|
protected $auth;
|
|
|
|
/**
|
|
* Create a new authentication controller instance.
|
|
*
|
|
* @param Guard $auth
|
|
* @return void
|
|
*/
|
|
public function __construct(Guard $auth)
|
|
{
|
|
$this->auth = $auth;
|
|
}
|
|
|
|
/**
|
|
* Show the application registration form.
|
|
*
|
|
* @Get("auth/register")
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function showRegistrationForm()
|
|
{
|
|
return view('auth.register');
|
|
}
|
|
|
|
/**
|
|
* Handle a registration request for the application.
|
|
*
|
|
* @Post("auth/register")
|
|
*
|
|
* @param RegisterRequest $request
|
|
* @return Response
|
|
*/
|
|
public function register(RegisterRequest $request)
|
|
{
|
|
// Registration form is valid, create user...
|
|
|
|
$this->auth->login($user);
|
|
|
|
return redirect('/');
|
|
}
|
|
|
|
/**
|
|
* Show the application login form.
|
|
*
|
|
* @Get("auth/login")
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function showLoginForm()
|
|
{
|
|
return view('auth.login');
|
|
}
|
|
|
|
/**
|
|
* Handle a login request to the application.
|
|
*
|
|
* @Post("auth/login")
|
|
*
|
|
* @param LoginRequest $request
|
|
* @return Response
|
|
*/
|
|
public function login(LoginRequest $request)
|
|
{
|
|
if ($this->auth->attempt($request->only('email', 'password')))
|
|
{
|
|
return redirect('/');
|
|
}
|
|
|
|
return redirect('/auth/login')->withErrors([
|
|
'email' => 'These credentials do not match our records.',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Log the user out of the application.
|
|
*
|
|
* @Get("auth/logout")
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function logout()
|
|
{
|
|
$this->auth->logout();
|
|
|
|
return redirect('/');
|
|
}
|
|
|
|
}
|