*/
public function socialRegister(string $socialDriver)
{
- $this->registrationService->checkRegistrationAllowed();
+ $this->registrationService->ensureRegistrationAllowed();
session()->put('social-callback', 'register');
return $this->socialAuthService->startRegister($socialDriver);
}
// Attempt login or fall-back to register if allowed.
$socialUser = $this->socialAuthService->getSocialUser($socialDriver);
- if ($action == 'login') {
+ if ($action === 'login') {
try {
return $this->socialAuthService->handleLoginCallback($socialDriver, $socialUser);
} catch (SocialSignInAccountNotUsed $exception) {
}
}
- if ($action == 'register') {
+ if ($action === 'register') {
return $this->socialRegisterCallback($socialDriver, $socialUser);
}
/**
* Register a new user after a registration callback.
- * @return RedirectResponse|Redirector
* @throws UserRegistrationException
*/
protected function socialRegisterCallback(string $socialDriver, SocialUser $socialUser)
$userData = [
'name' => $socialUser->getName(),
'email' => $socialUser->getEmail(),
- 'password' => Str::random(30)
+ 'password' => Str::random(32)
];
- try {
- $this->registrationService->registerUser($userData, $socialAccount, $emailVerified);
- } catch (UserRegistrationException $exception) {
- if ($exception->getMessage()) {
- $this->showErrorNotification($exception->getMessage());
- }
- return redirect($exception->redirectLocation);
+ // Take name from email address if empty
+ if (!$userData['name']) {
+ $userData['name'] = explode('@', $userData['email'])[0];
}
+ $user = $this->registrationService->registerUser($userData, $socialAccount, $emailVerified);
+ auth()->login($user);
+
$this->showSuccessNotification(trans('auth.register_success'));
return redirect('/');
}