-<?php
-
-namespace BookStack\Http\Controllers\Auth;
+<?php namespace BookStack\Http\Controllers\Auth;
+use BookStack\Exceptions\AuthException;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\Request;
use BookStack\Exceptions\SocialSignInException;
protected $redirectAfterLogout = '/login';
protected $username = 'email';
-
protected $socialAuthService;
protected $emailConfirmationService;
protected $userRepo;
$this->socialAuthService = $socialAuthService;
$this->emailConfirmationService = $emailConfirmationService;
$this->userRepo = $userRepo;
+ $this->redirectPath = baseUrl('/');
+ $this->redirectAfterLogout = baseUrl('/login');
$this->username = config('auth.method') === 'standard' ? 'email' : 'username';
parent::__construct();
}
* @param Request $request
* @param Authenticatable $user
* @return \Illuminate\Http\RedirectResponse
+ * @throws AuthException
*/
protected function authenticated(Request $request, Authenticatable $user)
{
}
if (!$user->exists) {
+
+ // Check for users with same email already
+ $alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
+ if ($alreadyUser) {
+ throw new AuthException('A user with the email ' . $user->email . ' already exists but with different credentials.');
+ }
+
$user->save();
$this->userRepo->attachDefaultRole($user);
auth()->login($user);
}
if (setting('registration-confirmation') || setting('registration-restrict')) {
- $newUser->email_confirmed = false;
$newUser->save();
$this->emailConfirmationService->sendConfirmation($newUser);
return redirect('/register/confirm');
}
- $newUser->email_confirmed = true;
-
auth()->login($newUser);
session()->flash('success', 'Thanks for signing up! You are now registered and signed in.');
return redirect($this->redirectPath());