3 namespace Oxbow\Http\Controllers\Auth;
5 use Oxbow\Exceptions\SocialSignInException;
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', ['only' => ['getLogin', 'postLogin', 'getRegister']]);
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 registration form.
77 * @return \Illuminate\Http\Response
79 public function getRegister()
81 $socialDrivers = $this->socialAuthService->getActiveDrivers();
82 return view('auth.register', ['socialDrivers' => $socialDrivers]);
86 * Show the application login form.
88 * @return \Illuminate\Http\Response
90 public function getLogin()
93 if (view()->exists('auth.authenticate')) {
94 return view('auth.authenticate');
97 $socialDrivers = $this->socialAuthService->getActiveDrivers();
98 return view('auth.login', ['socialDrivers' => $socialDrivers]);
102 * Redirect to the relevant social site.
103 * @param $socialDriver
104 * @return \Symfony\Component\HttpFoundation\RedirectResponse
106 public function getSocialLogin($socialDriver)
108 return $this->socialAuthService->startLogIn($socialDriver);
112 * The callback for social login services.
114 * @param $socialDriver
115 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
116 * @throws SocialSignInException
118 public function socialCallback($socialDriver)
120 return $this->socialAuthService->handleCallback($socialDriver);
124 * Detach a social account from a user.
125 * @param $socialDriver
126 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
128 public function detachSocialAccount($socialDriver)
130 return $this->socialAuthService->detachSocialAccount($socialDriver);