]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Auth/AuthController.php
Updated ldap so extension not required in testing
[bookstack] / app / Http / Controllers / Auth / AuthController.php
index fda0ee66842547d8819ba673f30a659230b2bcf0..beb191d624f1841169a17b5467aff9e28c9f3e4d 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace BookStack\Http\Controllers\Auth;
 
+use BookStack\Exceptions\AuthException;
+use BookStack\Exceptions\PrettyException;
 use Illuminate\Contracts\Auth\Authenticatable;
 use Illuminate\Http\Request;
 use BookStack\Exceptions\SocialSignInException;
@@ -115,6 +117,7 @@ class AuthController extends Controller
      * @param Request $request
      * @param Authenticatable $user
      * @return \Illuminate\Http\RedirectResponse
+     * @throws AuthException
      */
     protected function authenticated(Request $request, Authenticatable $user)
     {
@@ -132,6 +135,13 @@ class AuthController extends Controller
         }
 
         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);
@@ -184,14 +194,11 @@ class AuthController extends Controller
         }
 
         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());