3 namespace Oxbow\Http\Controllers\Auth;
5 use Oxbow\Exceptions\UserNotFound;
6 use Oxbow\Services\SocialAuthService;
9 use Oxbow\Http\Controllers\Controller;
10 use Illuminate\Foundation\Auth\ThrottlesLogins;
11 use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
13 class AuthController extends Controller
16 |--------------------------------------------------------------------------
17 | Registration & Login Controller
18 |--------------------------------------------------------------------------
20 | This controller handles the registration of new users, as well as the
21 | authentication of existing users. By default, this controller uses
22 | a simple trait to add these behaviors. Why don't you explore it?
26 use AuthenticatesAndRegistersUsers, ThrottlesLogins;
28 protected $loginPath = '/login';
29 protected $redirectPath = '/';
30 protected $redirectAfterLogout = '/login';
32 protected $socialAuthService;
35 * Create a new authentication controller instance.
36 * @param SocialAuthService $socialAuthService
38 public function __construct(SocialAuthService $socialAuthService)
40 $this->middleware('guest', ['except' => 'getLogout']);
41 $this->socialAuthService = $socialAuthService;
45 * Get a validator for an incoming registration request.
48 * @return \Illuminate\Contracts\Validation\Validator
50 protected function validator(array $data)
52 return Validator::make($data, [
53 'name' => 'required|max:255',
54 'email' => 'required|email|max:255|unique:users',
55 'password' => 'required|confirmed|min:6',
60 * Create a new user instance after a valid registration.
65 protected function create(array $data)
68 'name' => $data['name'],
69 'email' => $data['email'],
70 'password' => bcrypt($data['password']),
75 * Show the application login form.
77 * @return \Illuminate\Http\Response
79 public function getLogin()
82 if (view()->exists('auth.authenticate')) {
83 return view('auth.authenticate');
86 $socialDrivers = $this->socialAuthService->getActiveDrivers();
88 return view('auth.login', ['socialDrivers' => $socialDrivers]);
92 * Redirect to the relevant social site.
93 * @param $socialDriver
94 * @return \Symfony\Component\HttpFoundation\RedirectResponse
96 public function getSocialLogin($socialDriver)
98 return $this->socialAuthService->logIn($socialDriver);
102 * The callback for social login services.
104 * @param $socialDriver
105 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
106 * @throws UserNotFound
108 public function socialCallback($socialDriver)
110 $user = $this->socialAuthService->getUserFromCallback($socialDriver);
111 \Auth::login($user, true);
112 return redirect($this->redirectPath);