]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Auth/LoginController.php
add missing icon, fix name conventions
[bookstack] / app / Http / Controllers / Auth / LoginController.php
index 0de4a8282b9d61e0f9ffabe75093446996e6c7e0..106b905244229bf2fdf96f4d637bd2e6748be1a2 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace BookStack\Http\Controllers\Auth;
 
+use BookStack\Exceptions\AuthException;
 use BookStack\Http\Controllers\Controller;
 use BookStack\Repos\UserRepo;
 use BookStack\Services\SocialAuthService;
@@ -69,24 +70,25 @@ class LoginController extends Controller
     protected function authenticated(Request $request, Authenticatable $user)
     {
         // Explicitly log them out for now if they do no exist.
-        if (!$user->exists) auth()->logout($user);
+        if (!$user->exists) {
+            auth()->logout($user);
+        }
 
-        if (!$user->exists && $user->email === null && !$request->has('email')) {
+        if (!$user->exists && $user->email === null && !$request->filled('email')) {
             $request->flash();
             session()->flash('request-email', true);
             return redirect('/login');
         }
 
-        if (!$user->exists && $user->email === null && $request->has('email')) {
+        if (!$user->exists && $user->email === null && $request->filled('email')) {
             $user->email = $request->get('email');
         }
 
         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.');
+                throw new AuthException(trans('errors.error_user_exists_different_creds', ['email' => $user->email]));
             }
 
             $user->save();
@@ -101,12 +103,21 @@ class LoginController extends Controller
 
     /**
      * Show the application login form.
+     * @param Request $request
      * @return \Illuminate\Http\Response
      */
-    public function getLogin()
+    public function getLogin(Request $request)
     {
         $socialDrivers = $this->socialAuthService->getActiveDrivers();
         $authMethod = config('auth.method');
+
+        if ($request->has('email')) {
+            session()->flashInput([
+                'email' => $request->get('email'),
+                'password' => (config('app.env') === 'demo') ? $request->get('password', '') : ''
+            ]);
+        }
+
         return view('auth/login', ['socialDrivers' => $socialDrivers, 'authMethod' => $authMethod]);
     }
 
@@ -120,4 +131,4 @@ class LoginController extends Controller
         session()->put('social-callback', 'login');
         return $this->socialAuthService->startLogIn($socialDriver);
     }
-}
\ No newline at end of file
+}