]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/Access/RegistrationService.php
Fixes for CodeStyle vol.2
[bookstack] / app / Auth / Access / RegistrationService.php
index 9070d12415543410fff1cc3fa275a15af867f27c..16e3edbb44e8dc799c4bd3939a358d5d3b9b28df 100644 (file)
@@ -1,4 +1,6 @@
-<?php namespace BookStack\Auth\Access;
+<?php
+
+namespace BookStack\Auth\Access;
 
 use BookStack\Actions\ActivityType;
 use BookStack\Auth\SocialAccount;
@@ -6,11 +8,12 @@ use BookStack\Auth\User;
 use BookStack\Auth\UserRepo;
 use BookStack\Exceptions\UserRegistrationException;
 use BookStack\Facades\Activity;
+use BookStack\Facades\Theme;
+use BookStack\Theming\ThemeEvents;
 use Exception;
 
 class RegistrationService
 {
-
     protected $userRepo;
     protected $emailConfirmationService;
 
@@ -25,6 +28,7 @@ class RegistrationService
 
     /**
      * Check whether or not registrations are allowed in the app settings.
+     *
      * @throws UserRegistrationException
      */
     public function ensureRegistrationAllowed()
@@ -42,11 +46,13 @@ class RegistrationService
     {
         $authMethod = config('auth.method');
         $authMethodsWithRegistration = ['standard'];
+
         return in_array($authMethod, $authMethodsWithRegistration) && setting('registration-enabled');
     }
 
     /**
      * The registrations flow for all users.
+     *
      * @throws UserRegistrationException
      */
     public function registerUser(array $userData, ?SocialAccount $socialAccount = null, bool $emailConfirmed = false): User
@@ -71,6 +77,7 @@ class RegistrationService
         }
 
         Activity::add(ActivityType::AUTH_REGISTER, $socialAccount ?? $newUser);
+        Theme::dispatch(ThemeEvents::AUTH_REGISTER, $socialAccount ? $socialAccount->driver : auth()->getDefaultDriver(), $newUser);
 
         // Start email confirmation flow if required
         if ($this->emailConfirmationService->confirmationRequired() && !$emailConfirmed) {
@@ -81,6 +88,7 @@ class RegistrationService
                 session()->flash('sent-email-confirmation', true);
             } catch (Exception $e) {
                 $message = trans('auth.email_confirm_send_error');
+
                 throw new UserRegistrationException($message, '/register/confirm');
             }
         }
@@ -91,6 +99,7 @@ class RegistrationService
     /**
      * Ensure that the given email meets any active email domain registration restrictions.
      * Throws if restrictions are active and the email does not match an allowed domain.
+     *
      * @throws UserRegistrationException
      */
     protected function ensureEmailDomainAllowed(string $userEmail): void
@@ -102,9 +111,10 @@ class RegistrationService
         }
 
         $restrictedEmailDomains = explode(',', str_replace(' ', '', $registrationRestrict));
-        $userEmailDomain = $domain = mb_substr(mb_strrchr($userEmail, "@"), 1);
+        $userEmailDomain = $domain = mb_substr(mb_strrchr($userEmail, '@'), 1);
         if (!in_array($userEmailDomain, $restrictedEmailDomains)) {
             $redirect = $this->registrationAllowed() ? '/register' : '/login';
+
             throw new UserRegistrationException(trans('auth.registration_email_domain_invalid'), $redirect);
         }
     }