AuthController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use Auth;
  4. use App\User;
  5. use Validator;
  6. use App\Http\Controllers\Controller;
  7. use Illuminate\Foundation\Auth\ThrottlesLogins;
  8. use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
  9. class AuthController extends Controller
  10. {
  11. /*
  12. |--------------------------------------------------------------------------
  13. | Registration & Login Controller
  14. |--------------------------------------------------------------------------
  15. |
  16. | This controller handles the registration of new users, as well as the
  17. | authentication of existing users. By default, this controller uses
  18. | a simple trait to add these behaviors. Why don't you explore it?
  19. |
  20. */
  21. use AuthenticatesAndRegistersUsers, ThrottlesLogins;
  22. /**
  23. * Where to redirect users after login / registration.
  24. *
  25. * @var string
  26. */
  27. protected $redirectTo = '/admin_index';
  28. /**
  29. * Create a new authentication controller instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. $this->middleware('guest', ['except' => 'logout']);
  36. }
  37. /**
  38. * Get a validator for an incoming registration request.
  39. *
  40. * @param array $data
  41. * @return \Illuminate\Contracts\Validation\Validator
  42. */
  43. protected function validator(array $data)
  44. {
  45. return Validator::make($data, [
  46. 'name' => 'required|max:255',
  47. 'email' => 'required|email|max:255|unique:users',
  48. 'password' => 'required|confirmed|min:6',
  49. ]);
  50. }
  51. /**
  52. * Create a new user instance after a valid registration.
  53. *
  54. * @param array $data
  55. * @return User
  56. */
  57. protected function create(array $data)
  58. {
  59. return User::create([
  60. 'name' => $data['name'],
  61. 'email' => $data['email'],
  62. 'password' => bcrypt($data['password']),
  63. ]);
  64. }
  65. protected function register()
  66. {
  67. return view('auth.register');
  68. }
  69. protected function add_user()
  70. {
  71. return view('auth.register');
  72. }
  73. protected function logout()
  74. {
  75. Auth::logout();
  76. return redirect()->action('Auth\AuthController@showLoginForm');
  77. }
  78. }