/**
  * Handle the command.
  *
  * @param  CreateSubscriberCommand  $command
  * @return void
  */
 public function handle(CreateSubscriberCommand $command)
 {
     $subscriber = Subscribers::where('email', $command->email)->first();
     if ($subscriber) {
         if ($subscriber->status == "unsubscribed") {
             // Re-new subscription
             $subscriber->update(['status' => 'subscribed']);
             Event::fire(new SubscriberWasCreated($subscriber));
             return 'renew';
         } else {
             if (!$subscriber->confirmed && $subscriber->status == "subscribed") {
                 Event::fire(new SubscriberWasCreated($subscriber));
                 return 'thanks';
             } else {
                 if ($subscriber->confirmed && $subscriber->status == "subscribed") {
                     Event::fire(new SubscriberWasCreated($subscriber));
                     return 'confirmed';
                 }
             }
         }
     } else {
         $subscriber = Subscribers::create(['firstName' => $command->firstName, 'lastName' => $command->lastName, 'email' => $command->email, 'confirmation_code' => substr(md5(uniqid(rand(), true)), 16, 16)]);
         Event::fire(new SubscriberWasCreated($subscriber));
         return 'thanks';
     }
     return $subscriber;
 }
 /**
  * Handle the command.
  *
  * @param  ConfirmSubscriberCommand  $command
  * @return void
  */
 public function handle(ConfirmSubscriberCommand $command)
 {
     $subscriber = Subscribers::where('confirmation_code', '=', $command->confirmation_code)->first();
     if (!$subscriber) {
         return "false";
     }
     $subscriber->update(['confirmed' => '1']);
     Event::fire(new SubscriberWasConfirmed($subscriber));
 }
Ejemplo n.º 3
0
 public function unsubscribe($hash)
 {
     $email = base64_decode($hash);
     $subscribe = Subscribers::where('email', $email)->first();
     if ($subscribe) {
         $subscribe->delete();
         \Flash::success('All done!');
     }
     return redirect('/');
 }
 /**
  * Handle the command.
  *
  * @param  UnsubscribeSubscriberCommand  $command
  * @return void
  */
 public function handle(UnsubscribeSubscriberCommand $command)
 {
     $subscriber = Subscribers::where('confirmation_code', '=', $command->confirmation_code)->first();
     if (!$subscriber) {
         return false;
     }
     // Cancel subscription
     $subscriber->update(['status' => 'unsubscribed']);
     Event::fire(new SubscriberWasUnsubscribed($subscriber));
 }
 public function confirm($confirmation_code)
 {
     if (!$confirmation_code) {
         throw new InvalidConfirmationCodeException();
     }
     $subscriber = Subscribers::where('code', $confirmation_code)->first();
     if (!$subscriber) {
         throw new InvalidConfirmationCodeException();
     }
     $subscriber->confirmed = 1;
     $subscriber->code = null;
     $subscriber->save();
     return redirect('/')->with('email', 'Successfully confirmed email!');
 }