Showing
2 changed files
with
14 additions
and
0 deletions
app/Exceptions/AuthException.php
0 → 100644
| ... | @@ -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); | ... | ... |
-
Please register or sign in to post a comment