Changing default routing setup.
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
<?php namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use App\Http\Requests\Auth\RegisterRequest;
|
||||
|
||||
/**
|
||||
* @Middleware("guest", except={"logout"})
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('/');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
<?php namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Contracts\Auth\PasswordBroker;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* @Middleware("guest")
|
||||
*/
|
||||
class PasswordController extends Controller {
|
||||
|
||||
/**
|
||||
* The password broker implementation.
|
||||
*
|
||||
* @var PasswordBroker
|
||||
*/
|
||||
protected $passwords;
|
||||
|
||||
/**
|
||||
* Create a new password controller instance.
|
||||
*
|
||||
* @param PasswordBroker $passwords
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(PasswordBroker $passwords)
|
||||
{
|
||||
$this->passwords = $passwords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the form to request a password reset link.
|
||||
*
|
||||
* @Get("password/email")
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function showResetRequestForm()
|
||||
{
|
||||
return view('password.email');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reset link to the given user.
|
||||
*
|
||||
* @Post("password/email")
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function sendResetLink(Request $request)
|
||||
{
|
||||
switch ($response = $this->passwords->sendResetLink($request->only('email')))
|
||||
{
|
||||
case PasswordBroker::INVALID_USER:
|
||||
return redirect()->back()->with('error', trans($response));
|
||||
|
||||
case PasswordBroker::RESET_LINK_SENT:
|
||||
return redirect()->back()->with('status', trans($response));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the password reset view for the given token.
|
||||
*
|
||||
* @Get("password/reset/{token}")
|
||||
*
|
||||
* @param string $token
|
||||
* @return Response
|
||||
*/
|
||||
public function showResetForm($token = null)
|
||||
{
|
||||
if (is_null($token))
|
||||
{
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
return view('password.reset')->with('token', $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the given user's password.
|
||||
*
|
||||
* @Post("password/reset")
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function resetPassword(Request $request)
|
||||
{
|
||||
$credentials = $request->only(
|
||||
'email', 'password', 'password_confirmation', 'token'
|
||||
);
|
||||
|
||||
$response = $this->passwords->reset($credentials, function($user, $password)
|
||||
{
|
||||
$user->password = bcrypt($password);
|
||||
|
||||
$user->save();
|
||||
});
|
||||
|
||||
switch ($response)
|
||||
{
|
||||
case PasswordBroker::INVALID_PASSWORD:
|
||||
case PasswordBroker::INVALID_TOKEN:
|
||||
case PasswordBroker::INVALID_USER:
|
||||
return redirect()->back()->with('error', trans($response));
|
||||
|
||||
case PasswordBroker::PASSWORD_RESET:
|
||||
return redirect()->to('/');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user