Esempio n. 1
0
 public function sendVerification()
 {
     $confirmation_code = str_random(30);
     $user = User::find(Auth::user()->id);
     $user->confirmation_code = $confirmation_code;
     $user->save();
     $mail = new MailController();
     $mail->sendVerficationCode($confirmation_code);
     return true;
 }
 /**
  * Post
  *
  * @param Request $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function post(Request $request)
 {
     onlyAllowPostRequest($request);
     $all = $request->only(['title', 'content', 'author', 'base', 'group']);
     /**
      * Dữ liệu trả về
      */
     $response = new stdClass();
     /**
      * Kiểm tra user có tồn tại hay không?
      */
     $users = User::all()->where('id', intval($all['author']));
     if ($users->count() == 0) {
         //Không tồn tại người dùng
         $response->error = true;
         $response->error_msg = 'Đã có lỗi gì đó xảy ra!';
         return response()->json($response);
     }
     $u = $users->first();
     $email_u = $u->email;
     /**
      * Tạo post mới
      */
     $post = Post::create(['title' => ucfirst($all['title']), 'content' => ucfirst($all['content']), 'group' => intval($all['group']), 'author' => intval($all['author']), 'base' => $all['base']]);
     if ($all['base'] == 'class_xes') {
         /**
          * Thông báo qua email
          */
         $mail = new MailController();
         $arrEmail = ClassXController::getArrEmail(intval($all['group']));
         foreach ($arrEmail as $i => $a) {
             if ($a == $email_u) {
                 unset($arrEmail[$i]);
             }
         }
         $q = ClassX::all()->where('id', intval($all['group']))->first();
         $email_subject = 'Email được gửi từ ' . $q->name;
         $email_body = $u->name . ' gửi tới nội dung sau:<br>';
         $email_body .= '<p>' . ucfirst($all['content']) . '</p>';
         $mail->sendMail($email_subject, $email_body, $arrEmail);
     }
     /**
      * Post
      */
     $response->post = Post::getPostInfoById($post->id);
     $response->error = false;
     return response()->json($response);
 }
Esempio n. 3
0
 public function replyTopic(Request $request)
 {
     if (Auth::user()) {
         $reply = new TopicReply();
         $reply->topic_uuid = $request->uuid;
         $reply->uid = Auth::user()->uuid;
         $reply->body = clean($request->data);
         $reply->save();
         //Reviews
         if ($request->reviews) {
             $count = 0;
             foreach ($request->reviews as $review) {
                 $review_data[$count] = array('topic_uuid' => $request->uuid, 'user_uuid' => Auth::user()->uuid, 'criteria' => $review['criteria'], 'scores' => $review['scores'], 'topic_id' => $reply->id, 'is_template' => FALSE, 'created_at' => date("Y-m-d H:i:s"));
                 $count++;
             }
             Reviews::insert($review_data);
         }
         $replyObj = TopicReply::find($reply->id);
         $topic = new Topic();
         $author = $topic->getUserInfoFromTopic($request->uuid);
         //Mail
         $mailer = new MailController();
         //Mail to poster
         $mailer->notify_poster($request->uuid, $replyObj);
         //Mail to ppl who reply
         $mailer->notifiy_reply($request->uuid, $replyObj);
         //Add to notification
         /*$notification = new Notification();
           $notification->store(3,$request->topics_uid,
                               Auth::user()->uuid,
                               $request->topics_uid,
                               'reply');
           event(new \App\Events\TopicReplyEvent($request->uuid,$request->topics_uid,$replyObj));*/
     } else {
         echo "unauthorized";
     }
 }
Esempio n. 4
0
 /**
  * Creates a ticket for the event for the logged-in user, or if the user
  * already has a ticket, return theirs.
  *
  * @param  Integer 	$eventId 	ID of the event for the ticket.
  * @return View 		        Ticket View
  */
 public function store()
 {
     $data = Request::only(["event_id", "stripeToken"]);
     try {
         $event = Event::findOrFail($data["event_id"]);
     } catch (ModelNotFoundException $e) {
         return Redirect::back()->withErrors(['message' => $this->errorMessages['event_not_found']]);
     }
     $user = Auth::user();
     if (Ticket::where('event_id', $event->id)->where('user_id', $user->id)->get()->toArray()) {
         return Redirect::back()->withErrors(["message" => $this->errorMessages['ticket_exists']]);
     }
     if ($event->price > 0) {
         // If the ticket ain't free you're going to have to pay for it.
         // Let's Stripe.
         Stripe::setApiKey(env('STRIPE_SECRET'));
         try {
             // Create a reference for a Customer relating to the Stripe token we received
             $customer = Customer::create(["email" => $user->email, "card" => $data["stripeToken"]]);
             // Now, charge that customer for the ticket as expected.
             $charge = Charge::create(["customer" => $customer->id, "amount" => $event->price * 100, "currency" => "eur"]);
         } catch (Error\Card $e) {
             return Redirect::back()->withErrors(["message" => $this->errorMessages['card_declined']]);
         } catch (Error\RateLimit $e) {
             return \Redirect::back()->withErrors(["message" => $this->errorMessages['server_error']]);
         } catch (Error\InvalidRequest $e) {
             dd($e);
             return Redirect::back()->withErrors(["message" => $this->errorMessages['dev_mistake']]);
         } catch (Error\Authentication $e) {
             return Redirect::back()->withErrors(["message" => $this->errorMessages['dev_mistake_auth']]);
         } catch (Error\ApiConnection $e) {
             return Redirect::back()->withErrors(["message" => $this->errorMessages['network_error']]);
         } catch (Error\Base $e) {
             // I actually don't know what this error means
             // or what it does, so probably panic
             return Redirect::back()->withErrors(["message" => $this->errorMessages['something_wrong']]);
         }
         $ticket = Ticket::create(["user_id" => $user->id, "event_id" => $event->id, "price" => $event->price, "used" => false, "printed" => false, "charge_id" => $charge->id]);
     } else {
         $ticket = Ticket::create(["user_id" => $user->id, "event_id" => $event->id, "price" => $event->price, "used" => false, "printed" => false, "charge_id" => null]);
     }
     MailController::sendTicket($ticket);
     return Redirect::back()->with('message', "You've got a ticket! Find your details and print it out here.");
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     MailController::previsaodechegada();
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     MailController::enviarprealerta();
 }