Dan Brown

Added a friendlier error for LDAP new user mismatches

1 +<?php namespace BookStack\Exceptions;
2 +
3 +
4 +class AuthException extends PrettyException {}
...\ No newline at end of file ...\ No newline at end of file
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
2 2
3 namespace BookStack\Http\Controllers\Auth; 3 namespace BookStack\Http\Controllers\Auth;
4 4
5 +use BookStack\Exceptions\AuthException;
6 +use BookStack\Exceptions\PrettyException;
5 use Illuminate\Contracts\Auth\Authenticatable; 7 use Illuminate\Contracts\Auth\Authenticatable;
6 use Illuminate\Http\Request; 8 use Illuminate\Http\Request;
7 use BookStack\Exceptions\SocialSignInException; 9 use BookStack\Exceptions\SocialSignInException;
...@@ -115,6 +117,7 @@ class AuthController extends Controller ...@@ -115,6 +117,7 @@ class AuthController extends Controller
115 * @param Request $request 117 * @param Request $request
116 * @param Authenticatable $user 118 * @param Authenticatable $user
117 * @return \Illuminate\Http\RedirectResponse 119 * @return \Illuminate\Http\RedirectResponse
120 + * @throws AuthException
118 */ 121 */
119 protected function authenticated(Request $request, Authenticatable $user) 122 protected function authenticated(Request $request, Authenticatable $user)
120 { 123 {
...@@ -132,6 +135,13 @@ class AuthController extends Controller ...@@ -132,6 +135,13 @@ class AuthController extends Controller
132 } 135 }
133 136
134 if (!$user->exists) { 137 if (!$user->exists) {
138 +
139 + // Check for users with same email already
140 + $alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
141 + if ($alreadyUser) {
142 + throw new AuthException('A user with the email ' . $user->email . ' already exists but with different credentials.');
143 + }
144 +
135 $user->save(); 145 $user->save();
136 $this->userRepo->attachDefaultRole($user); 146 $this->userRepo->attachDefaultRole($user);
137 auth()->login($user); 147 auth()->login($user);
......