コード例 #1
0
 /**
  * This middleware checks that a guest user is indeed checking out
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // only non-authenticated users should be allowed to checkout as guests
     if (is_null($request->user())) {
         // For a successful guest checkout to be initialized, we pass in an allow=1 param into the url
         // This is because later, the checkout cookie will be used to verify that the user is a guest, and for now
         // it does not exist until the user fills in the guest user details form
         if ($request->get('allow') === "1" & empty($this->guest->getCookieData())) {
             return $next($request);
         }
         // by the time this statement is executed, the cookie exists, so we do the normal check
         if ($this->guest->isAGuest()) {
             return $next($request);
         }
         return redirect()->guest(route('checkout.auth'));
     }
     // if the user is authenticated, then we skip step1 of checkout, which is filling in guest data
     return redirect()->route('u.checkout.step2');
 }
コード例 #2
0
 /**
  * This will allow users to optionally create an account before making an order
  *
  * @param GuestCreateAccount $guestCreateAccount
  * @param CreateAccount $user
  *
  * @param UserRepository $registerUser
  * @return mixed
  */
 public function createAccount(GuestCreateAccount $guestCreateAccount, CreateAccount $user, UserRepository $registerUser)
 {
     // check the email
     $email = $this->guest->getGuestDetails()->email;
     $result = $registerUser->getFirstBy('email', '=', $email);
     if (!is_null($result)) {
         flash()->warning('Your email address is already in use. Please change it');
         return redirect()->back();
     }
     return $user->createAccount($guestCreateAccount, $registerUser)->handleRedirect($guestCreateAccount);
 }