]> BookStack Code Mirror - bookstack/commitdiff
Added a friendlier error for LDAP new user mismatches
authorDan Brown <redacted>
Sun, 3 Apr 2016 10:16:49 +0000 (11:16 +0100)
committerDan Brown <redacted>
Sun, 3 Apr 2016 10:16:49 +0000 (11:16 +0100)
app/Exceptions/AuthException.php [new file with mode: 0644]
app/Http/Controllers/Auth/AuthController.php

diff --git a/app/Exceptions/AuthException.php b/app/Exceptions/AuthException.php
new file mode 100644 (file)
index 0000000..c20bb62
--- /dev/null
@@ -0,0 +1,4 @@
+<?php namespace BookStack\Exceptions;
+
+
+class AuthException extends PrettyException {}
\ No newline at end of file
index fda0ee66842547d8819ba673f30a659230b2bcf0..ef44b2aef9834f62920338c211086223c9cf761e 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);