AuthController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php namespace App\Http\Controllers;
  2. use App\Http\Requests\LoginRequest;
  3. use Illuminate\Contracts\Auth\Guard;
  4. use App\Http\Requests\RegisterRequest;
  5. class AuthController extends Controller {
  6. /**
  7. * The Guard implementation.
  8. *
  9. * @var Guard
  10. */
  11. protected $auth;
  12. /**
  13. * Create a new authentication controller instance.
  14. *
  15. * @param Guard $auth
  16. * @return void
  17. */
  18. public function __construct(Guard $auth)
  19. {
  20. $this->auth = $auth;
  21. $this->middleware('guest', ['except' => 'getLogout']);
  22. }
  23. /**
  24. * Show the application registration form.
  25. *
  26. * @return Response
  27. */
  28. public function getRegister()
  29. {
  30. return view('auth.register');
  31. }
  32. /**
  33. * Handle a registration request for the application.
  34. *
  35. * @param RegisterRequest $request
  36. * @return Response
  37. */
  38. public function postRegister(RegisterRequest $request)
  39. {
  40. // Registration form is valid, create user...
  41. $this->auth->login($user);
  42. return redirect('/');
  43. }
  44. /**
  45. * Show the application login form.
  46. *
  47. * @return Response
  48. */
  49. public function getLogin()
  50. {
  51. return view('auth.login');
  52. }
  53. /**
  54. * Handle a login request to the application.
  55. *
  56. * @param LoginRequest $request
  57. * @return Response
  58. */
  59. public function postLogin(LoginRequest $request)
  60. {
  61. if ($this->auth->attempt($request->only('email', 'password')))
  62. {
  63. return redirect('/');
  64. }
  65. return redirect('/auth/login')->withErrors([
  66. 'email' => 'These credentials do not match our records.',
  67. ]);
  68. }
  69. /**
  70. * Log the user out of the application.
  71. *
  72. * @return Response
  73. */
  74. public function getLogout()
  75. {
  76. $this->auth->logout();
  77. return redirect('/');
  78. }
  79. }