/**
  * 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!');
 }
Ejemplo n.º 6
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     //
     $rules = ['email' => 'required|unique:subscribers|email', 'place' => 'required'];
     $messages = ['email.unique' => 'You are already subscribed!'];
     $validator = Validator::make($request->all(), $rules, $messages);
     if ($validator->fails()) {
         return redirect('/')->withErrors($validator)->withInput();
     }
     $input = Input::all();
     //var_dump($input);
     Subscribers::create($input);
     return redirect('/')->with('status', 'Successfully subscribed!');
 }
Ejemplo n.º 7
0
 /**
  * Emails to subscribers
  *
  * @param Articles $article
  */
 public function sendEmails(Articles $article)
 {
     $subscribers = Subscribers::all();
     foreach ($subscribers as $subscriber) {
         Mail::send('layouts.email', compact('subscriber', 'article'), function ($m) use($subscriber, $article) {
             $m->to($subscriber->email, $subscriber->email)->subject($article->title);
         });
     }
 }