]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Auth/ConfirmEmailController.php
Fixes for CodeStyle vol.2
[bookstack] / app / Http / Controllers / Auth / ConfirmEmailController.php
index bffeb5f61b2f2f7528b87e6ad506f4b6dded53d2..02b9ef2760559e247f8f159a8f014732d571b76b 100644 (file)
@@ -3,6 +3,7 @@
 namespace BookStack\Http\Controllers\Auth;
 
 use BookStack\Auth\Access\EmailConfirmationService;
+use BookStack\Auth\Access\LoginService;
 use BookStack\Auth\UserRepo;
 use BookStack\Exceptions\ConfirmationEmailException;
 use BookStack\Exceptions\UserTokenExpiredException;
@@ -17,18 +18,22 @@ use Illuminate\View\View;
 class ConfirmEmailController extends Controller
 {
     protected $emailConfirmationService;
+    protected $loginService;
     protected $userRepo;
 
     /**
      * Create a new controller instance.
      */
-    public function __construct(EmailConfirmationService $emailConfirmationService, UserRepo $userRepo)
-    {
+    public function __construct(
+        EmailConfirmationService $emailConfirmationService,
+        LoginService $loginService,
+        UserRepo $userRepo
+    ) {
         $this->emailConfirmationService = $emailConfirmationService;
+        $this->loginService = $loginService;
         $this->userRepo = $userRepo;
     }
 
-
     /**
      * Show the page to tell the user to check their email
      * and confirm their address.
@@ -41,19 +46,23 @@ class ConfirmEmailController extends Controller
     /**
      * Shows a notice that a user's email address has not been confirmed,
      * Also has the option to re-send the confirmation email.
-     * @return View
      */
     public function showAwaiting()
     {
-        return view('auth.user-unconfirmed');
+        $user = $this->loginService->getLastLoginAttemptUser();
+
+        return view('auth.user-unconfirmed', ['user' => $user]);
     }
 
     /**
      * Confirms an email via a token and logs the user into the system.
+     *
      * @param $token
-     * @return RedirectResponse|Redirector
+     *
      * @throws ConfirmationEmailException
      * @throws Exception
+     *
+     * @return RedirectResponse|Redirector
      */
     public function confirm($token)
     {
@@ -62,6 +71,7 @@ class ConfirmEmailController extends Controller
         } catch (Exception $exception) {
             if ($exception instanceof UserTokenNotFoundException) {
                 $this->showErrorNotification(trans('errors.email_confirmation_invalid'));
+
                 return redirect('/register');
             }
 
@@ -69,6 +79,7 @@ class ConfirmEmailController extends Controller
                 $user = $this->userRepo->getById($exception->userId);
                 $this->emailConfirmationService->sendConfirmation($user);
                 $this->showErrorNotification(trans('errors.email_confirmation_expired'));
+
                 return redirect('/register/confirm');
             }
 
@@ -79,23 +90,24 @@ class ConfirmEmailController extends Controller
         $user->email_confirmed = true;
         $user->save();
 
-        auth()->login($user);
-        $this->showSuccessNotification(trans('auth.email_confirm_success'));
         $this->emailConfirmationService->deleteByUser($user);
+        $this->showSuccessNotification(trans('auth.email_confirm_success'));
+        $this->loginService->login($user, auth()->getDefaultDriver());
 
         return redirect('/');
     }
 
-
     /**
-     * Resend the confirmation email
+     * Resend the confirmation email.
+     *
      * @param Request $request
+     *
      * @return View
      */
     public function resend(Request $request)
     {
         $this->validate($request, [
-            'email' => 'required|email|exists:users,email'
+            'email' => 'required|email|exists:users,email',
         ]);
         $user = $this->userRepo->getByEmail($request->get('email'));
 
@@ -103,10 +115,12 @@ class ConfirmEmailController extends Controller
             $this->emailConfirmationService->sendConfirmation($user);
         } catch (Exception $e) {
             $this->showErrorNotification(trans('auth.email_confirm_send_error'));
+
             return redirect('/register/confirm');
         }
 
         $this->showSuccessNotification(trans('auth.email_confirm_resent'));
+
         return redirect('/register/confirm');
     }
 }