Changing default routing setup.
This commit is contained in:
94
app/Http/Controllers/AuthController.php
Normal file
94
app/Http/Controllers/AuthController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use App\Http\Requests\Auth\RegisterRequest;
|
||||
|
||||
class AuthController extends Controller {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$this->middleware('guest', ['except' => 'logout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(RegisterRequest $request)
|
||||
{
|
||||
// Registration form is valid, create user...
|
||||
|
||||
$this->auth->login($user);
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(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.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function getLogout()
|
||||
{
|
||||
$this->auth->logout();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user