]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Auth/ConfirmEmailController.php
Apply fixes from StyleCI
[bookstack] / app / Http / Controllers / Auth / ConfirmEmailController.php
index 099558eb77fdce133b307aaac327277bc02510f8..63f220a68e5630e106fcf51dbc4488ea0a65db04 100644 (file)
@@ -2,12 +2,15 @@
 
 namespace BookStack\Http\Controllers\Auth;
 
+use BookStack\Actions\ActivityType;
 use BookStack\Auth\Access\EmailConfirmationService;
 use BookStack\Auth\UserRepo;
 use BookStack\Exceptions\ConfirmationEmailException;
 use BookStack\Exceptions\UserTokenExpiredException;
 use BookStack\Exceptions\UserTokenNotFoundException;
+use BookStack\Facades\Theme;
 use BookStack\Http\Controllers\Controller;
+use BookStack\Theming\ThemeEvents;
 use Exception;
 use Illuminate\Http\RedirectResponse;
 use Illuminate\Http\Request;
@@ -21,18 +24,13 @@ class ConfirmEmailController extends Controller
 
     /**
      * Create a new controller instance.
-     *
-     * @param EmailConfirmationService $emailConfirmationService
-     * @param UserRepo $userRepo
      */
     public function __construct(EmailConfirmationService $emailConfirmationService, UserRepo $userRepo)
     {
         $this->emailConfirmationService = $emailConfirmationService;
         $this->userRepo = $userRepo;
-        parent::__construct();
     }
 
-
     /**
      * Show the page to tell the user to check their email
      * and confirm their address.
@@ -45,6 +43,7 @@ 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()
@@ -54,10 +53,13 @@ class ConfirmEmailController extends Controller
 
     /**
      * 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)
     {
@@ -66,6 +68,7 @@ class ConfirmEmailController extends Controller
         } catch (Exception $exception) {
             if ($exception instanceof UserTokenNotFoundException) {
                 $this->showErrorNotification(trans('errors.email_confirmation_invalid'));
+
                 return redirect('/register');
             }
 
@@ -73,6 +76,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');
             }
 
@@ -84,22 +88,25 @@ class ConfirmEmailController extends Controller
         $user->save();
 
         auth()->login($user);
+        Theme::dispatch(ThemeEvents::AUTH_LOGIN, auth()->getDefaultDriver(), $user);
+        $this->logActivity(ActivityType::AUTH_LOGIN, $user);
         $this->showSuccessNotification(trans('auth.email_confirm_success'));
         $this->emailConfirmationService->deleteByUser($user);
 
         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'));
 
@@ -107,10 +114,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');
     }
 }