Ejemplo n.º 1
0
 /**
  * Handle the unsubscribe.
  *
  * @param string|null $code
  *
  * @return \Illuminate\View\View
  */
 public function getUnsubscribe($code = null)
 {
     if (is_null($code)) {
         throw new NotFoundHttpException();
     }
     $subscriber = Subscriber::where('verify_code', '=', $code)->first();
     if (!$subscriber || !$subscriber->verified()) {
         return Redirect::route('status-page');
     }
     $subscriber->delete();
     return Redirect::route('status-page')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsuscribed')));
 }
Ejemplo n.º 2
0
 /**
  * Handle the unsubscribe.
  *
  * @param string|null $code
  *
  * @return \Illuminate\View\View
  */
 public function getUnsubscribe($code = null)
 {
     if ($code === null) {
         throw new NotFoundHttpException();
     }
     $subscriber = Subscriber::where('verify_code', '=', $code)->first();
     if (!$subscriber || !$subscriber->is_verified) {
         throw new BadRequestHttpException();
     }
     dispatch(new UnsubscribeSubscriberCommand($subscriber));
     return Redirect::route('status-page')->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsubscribed')));
 }
 /**
  * Handle the subscribe subscriber command.
  *
  * @param \CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand $command
  *
  * @throws \CachetHQ\Cachet\Exceptions\AlreadySubscribedException
  *
  * @return \CachetHQ\Cachet\Models\Subscriber
  */
 public function handle(SubscribeSubscriberCommand $command)
 {
     if (Subscriber::where('email', $command->email)->first()) {
         throw new AlreadySubscribedException("Cannot subscribe {$command->email} because they're already subscribed.");
     }
     $subscriber = Subscriber::create(['email' => $command->email]);
     if ($command->verified) {
         $this->dispatch(new VerifySubscriberCommand($subscriber));
     } else {
         event(new SubscriberHasSubscribedEvent($subscriber));
     }
     return $subscriber;
 }
 /**
  * Handle the subscribe subscriber command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Subscriber
  */
 public function handle(SubscribeSubscriberCommand $command)
 {
     if ($subscriber = Subscriber::where('email', $command->email)->first()) {
         return $subscriber;
     }
     $subscriber = Subscriber::firstOrCreate(['email' => $command->email]);
     // Decide what to subscribe the subscriber to.
     if ($subscriptions = $command->subscriptions) {
         $subscriptions = Component::whereIn('id', $subscriptions);
     } else {
         $subscriptions = Component::all();
     }
     foreach ($subscriptions as $component) {
         Subscription::create(['subscriber_id' => $subscriber->id, 'component_id' => $component->id]);
     }
     if ($command->verified) {
         dispatch(new VerifySubscriberCommand($subscriber));
     } else {
         event(new SubscriberHasSubscribedEvent($subscriber));
     }
     return $subscriber;
 }
 /**
  * Handle the subscribe subscriber command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand $command
  *
  * @throws \CachetHQ\Cachet\Exceptions\AlreadySubscribedException
  *
  * @return \CachetHQ\Cachet\Models\Subscriber
  */
 public function handle(SubscribeSubscriberCommand $command)
 {
     if (Subscriber::where('email', $command->email)->first() && $command->subscriptions === null) {
         throw new AlreadySubscribedException("Cannot subscribe {$command->email} because they're already subscribed.");
     }
     $subscriber = Subscriber::firstOrCreate(['email' => $command->email]);
     if ($subscriptions = $command->subscriptions) {
         foreach ($subscriptions as $subscription => $subscriptionValue) {
             Subscription::firstOrCreate(['subscriber_id' => $subscriber->id, $subscription => $subscriptionValue]);
         }
     }
     if ($subscriber->is_verified === false) {
         if ($command->verified) {
             dispatch(new VerifySubscriberCommand($subscriber));
         } else {
             event(new SubscriberHasSubscribedEvent($subscriber));
         }
     } else {
         event(new SubscriberHasUpdatedSubscriptionsEvent($subscriber));
     }
     return $subscriber;
 }
Ejemplo n.º 6
0
 /**
  * Updates the subscription manager for a subscriber.
  *
  * @param string|null $code
  *
  * @return \Illuminate\View\View
  */
 public function postManage($code = null)
 {
     if ($code === null) {
         throw new NotFoundHttpException();
     }
     $subscriber = Subscriber::where('verify_code', '=', $code)->first();
     if (!$subscriber) {
         throw new BadRequestHttpException();
     }
     try {
         dispatch(new UpdateSubscriberSubscriptionCommand($subscriber, Binput::get('subscriptions')));
     } catch (ValidationException $e) {
         dd($e->getMessageBag());
         return Redirect::route('subscribe.manage', $subscriber->verify_code)->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('cachet.subscriber.email.failure')))->withErrors($e->getMessageBag());
     }
     return Redirect::route('subscribe.manage', $subscriber->verify_code)->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.subscribed')));
 }
Ejemplo n.º 7
0
 /**
  * Shows the subscription manager page.
  *
  * @param string|null $code
  *
  * @return \Illuminate\View\View
  */
 public function showManage($code = null)
 {
     if ($code === null) {
         throw new NotFoundHttpException();
     }
     $subscriber = Subscriber::where('verify_code', '=', $code)->first();
     if (!$subscriber || !$subscriber->is_verified) {
         throw new BadRequestHttpException();
     }
     return View::make('subscribe.manage')->withSubscriber($subscriber);
 }