Ejemplo n.º 1
0
 /**
  * Send the response after the user was authenticated.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  bool  $throttles
  * @return \Illuminate\Http\Response
  */
 protected function handleUserWasAuthenticated(Request $request, $throttles)
 {
     if ($throttles) {
         $this->clearLoginAttempts($request);
     }
     if (method_exists($this, 'authenticated')) {
         return $this->authenticated($request, Auth::user());
     }
     Redis::publish('connected', Auth::user());
     return redirect()->intended($this->redirectPath());
 }
Ejemplo n.º 2
0
 public static function boot()
 {
     parent::boot();
     Project::updating(function ($project) {
         $msg = "<a href='/projects/{$project->id}'>The project: {$project->name} was updated.</a>";
         Redis::lpush('messages', $msg);
         Redis::publish('new-message', $msg);
     });
     Project::creating(function ($project) {
         $msg = "<a href='/projects/{$project->id}'>The project: {$project->name} was created.</a>";
         Redis::lpush('messages', $msg);
         Redis::publish('new-message', $msg);
     });
 }
Ejemplo n.º 3
0
 public static function boot()
 {
     parent::boot();
     Task::updating(function ($task) {
         $project = $task->project()->get()[0];
         $msg = "<a href='/projects/{$project->id}'>The task, {$task->name}, on {$project->name} was updated.</a>";
         Redis::lpush('messages', $msg);
         Redis::publish('new-message', $msg);
     });
     Task::creating(function ($task) {
         $project = $task->project()->get()[0];
         $msg = "<a href='/projects/{$project->id}'>The task, {$task->name}, on {$project->name} was created.</a>";
         Redis::lpush('messages', $msg);
         Redis::publish('new-message', $msg);
     });
 }
Ejemplo n.º 4
0
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    /*
     * Goals for the demonstration of combining Laravel, Redis, Node & Socket.io
     */
    // 1. Publish Event with Redis
    /*
     * 1.1 Setup some dummy data; this would be a full event or object model in real life
     */
    $data = ['event' => 'UserSignedUp', 'data' => ['username' => 'John Doe']];
    /*
     * 1.2 Publish the event to the Redis 'test-channel' by JSON encoding the data into Redis
     */
    Redis::publish('test-channel', json_encode($data));
    // 2. Node.js + Redis subscribes to even
    /*
     * Node will run from the project root folder's 'socket.js' file to
     *   Read from Redis
     *   Broadcast the event on Socket.io
     *
     * See the socket.js file in the project root
     * This file must be triggered with `node socket.js` in order to setup the node server
     */
    // 3. Use Socket.io to emit to all clients
    /*
     * Added the emit event from Socket.io on the server side to the socket.js file
     *
     * The next step is to add in the client side socket.io
     */
Ejemplo n.º 5
0
 public function create_transaction($domain, Request $request)
 {
     if ($this->user->status == 2) {
         return $this->responseBadRequest('Nhân viên này đang chuyển tiền.');
     } else {
         $this->user->status = 2;
         $this->user->save();
         $transaction = new Transaction();
         $transaction->status = 0;
         $transaction->sender_id = $this->user->id;
         $transaction->receiver_id = $request->receiver_id;
         $transaction->receiver_money = User::find($request->receiver_id)->money;
         $transaction->money = $this->user->money;
         $transaction->save();
         $notification = new Notification();
         $notification->product_id = $transaction->id;
         $notification->actor_id = $this->user->id;
         $notification->receiver_id = $request->receiver_id;
         $notification->type = 3;
         $notification->save();
         $data = array("message" => $notification->actor->name . " vừa chuyển tiền cho bạn và đang chờ bạn xác nhận.", "link" => "", 'transaction' => ['id' => $transaction->id, 'sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money], 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
         $publish_data = array("event" => "notification", "data" => $data);
         Redis::publish('colorme-channel', json_encode($publish_data));
         $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]);
         Redis::publish('colorme-channel', json_encode($publish_data));
         return $this->respond(['transaction' => ['sender' => $transaction->sender->name, 'receiver' => $transaction->receiver->name, 'status' => transaction_status_raw($transaction->status), 'money' => $transaction->money]]);
     }
 }
Ejemplo n.º 6
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function test()
 {
     $data = ['name' => 'Dimas'];
     Redis::publish('chat-channel', json_encode($data));
     return Redis::get('name');
 }
Ejemplo n.º 7
0
 public function store_comment(Request $request)
 {
     $comment_content = $request->comment_content;
     $product_id = $request->product_id;
     //send one notifcation to author
     if (Product::find($product_id)->author->id != $this->user->id) {
         $notification = new Notification();
         $notification->product_id = $request->product_id;
         $notification->actor_id = $this->user->id;
         $notification->receiver_id = Product::find($product_id)->author->id;
         $notification->type = 1;
         $notification->save();
         $data = array("message" => $notification->actor->name . " đã bình luận về bài viết của bạn", "link" => url('bai-tap-colorme?id=' . $notification->product_id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
         $publish_data = array("event" => "notification", "data" => $data);
         Redis::publish('colorme-channel', json_encode($publish_data));
     }
     $product = Product::find($product_id);
     $already_sent_noti = array();
     //send to all others that involve in the post
     foreach ($product->comments as $comment) {
         $commenter_id = $comment->commenter_id;
         if ($product->author->id != $commenter_id && $commenter_id != $this->user->id && !in_array($commenter_id, $already_sent_noti)) {
             $notification = new Notification();
             $notification->product_id = $request->product_id;
             $notification->actor_id = $this->user->id;
             $notification->receiver_id = $commenter_id;
             $notification->type = 2;
             $notification->save();
             $data = array("message" => $notification->actor->name . " cũng đã bình luận về bài viết mà bạn đã bình luận", "link" => url('bai-tap-colorme?id=' . $notification->product_id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
             $publish_data = array("event" => "notification", "data" => $data);
             Redis::publish('colorme-channel', json_encode($publish_data));
             $already_sent_noti[] = $commenter_id;
         }
     }
     $comment = new Comment();
     $comment->product_id = $product_id;
     $comment->commenter_id = $this->user->id;
     $comment->content = $comment_content;
     $comment->save();
     $view = View::make('components.comment_item', ['comment' => $comment]);
     $contents = $view->render();
     $publish_data = array("event" => "comment", "data" => $contents);
     Redis::publish('colorme-channel', json_encode($publish_data));
     return time_elapsed_string(strtotime($comment->created_at));
 }
Ejemplo n.º 8
0
 public function setRoom(Request $request)
 {
     $user = Auth::user();
     //        $user->setRoom($request->get('room'));
     Redis::publish('room', $request->get('room'));
 }
Ejemplo n.º 9
0
 public function remove_shift_regis(Request $request)
 {
     $shift_id = $request->shift_id;
     $shift = Shift::find($shift_id);
     $shift->user_id = 0;
     $shift->save();
     $shift_pick = new ShiftPick();
     $shift_pick->user_id = $this->user->id;
     $shift_pick->shift_id = $shift->id;
     $shift_pick->status = 0;
     $shift_pick->save();
     $data = json_encode(["id" => $shift->id]);
     $publish_data = array("event" => "remove-shift", "data" => $data);
     Redis::publish('colorme-channel', json_encode($publish_data));
     return response()->json(['message' => "Bỏ đăng ký thành công", 'status' => 1]);
 }
Ejemplo n.º 10
0
 public function receive_video_convert_notifications()
 {
     $post = file_get_contents('php://input');
     $test = new Test();
     $test->content = $post;
     $test->save();
     $noti = json_decode($post);
     $message = json_decode($noti->Message);
     $jobId = $message->jobId;
     $video_name = '/videos/' . $message->outputs[0]->key;
     $video_url = config('app.s3_url') . $video_name;
     $publish_data = array("event" => "transcode-video", "data" => ["video_url" => $video_url, 'video_name' => $video_name, 'jobId' => $jobId, 'thumb_url' => $video_url]);
     Redis::publish('colorme-channel', json_encode($publish_data));
     $tmp_file_name = "/" . $message->input->key;
     $s3 = \Illuminate\Support\Facades\Storage::disk('s3');
     $s3->delete($tmp_file_name);
     return "done";
 }
Ejemplo n.º 11
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $request = $this->prepareRequest($request);
     $msg = Message::create($request->all())->load('author');
     Redis::publish('default_room', $msg);
 }
Ejemplo n.º 12
0
 public function test()
 {
     $data = ['event' => 'UserSignedUp', 'data' => ['username' => 'John Doe']];
     Redis::publish('test-channel', json_encode($data));
     return view('manage.test');
     //
     //        Cache::put('foo','bar',10);
     //        return Cache::get('foo');
     //        Redis::set('name','quan');
     //        return Redis::get('name');
     //        $class_id = 15;
     //        $class = StudyClass::find($class_id);
     ////        dd($class->registers);
     //        foreach ($class->registers as $regis) {
     //            send_mail_activate_class($regis, ['*****@*****.**']);
     //        }
     //        $data['class'] = $class;
     //        $data['student'] = $this->user;
 }
Ejemplo n.º 13
0
 public function handleMessage(Request $request)
 {
     $msg = $request->input('message');
     Redis::publish('test-channel', $msg);
 }
Ejemplo n.º 14
0
 public function comment($domain, $productId, Request $request)
 {
     $comment_content = $request->comment_content;
     $product = Product::find($productId);
     //send one notifcation to author
     if ($product->author->id != $this->user->id) {
         $notification = new Notification();
         $notification->product_id = $productId;
         $notification->actor_id = $this->user->id;
         $notification->receiver_id = Product::find($productId)->author->id;
         $notification->type = 1;
         $notification->save();
         $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]);
         Redis::publish('colorme-channel', json_encode($publish_data));
         send_push_notification(json_encode($publish_data));
     }
     $already_sent_noti = array();
     //send to all others that involve in the post
     foreach ($product->comments as $comment) {
         $commenter_id = $comment->commenter_id;
         if ($product->author->id != $commenter_id && $commenter_id != $this->user->id && !in_array($commenter_id, $already_sent_noti)) {
             $notification = new Notification();
             $notification->product_id = $productId;
             $notification->actor_id = $this->user->id;
             $notification->receiver_id = $commenter_id;
             $notification->type = 2;
             $notification->save();
             $publish_data = array("event" => "notification", "data" => ["notification" => $this->notificationTransformer->transform($notification)]);
             Redis::publish('colorme-channel', json_encode($publish_data));
             send_push_notification(json_encode($publish_data));
             $already_sent_noti[] = $commenter_id;
         }
     }
     $comment = new Comment();
     $comment->product_id = $productId;
     $comment->commenter_id = $this->user->id;
     $comment->content = $comment_content;
     $comment->save();
     $publish_data = array("event" => "comment", "data" => json_encode(["comment" => $this->commentTransformer->transform($comment), "product_id" => $productId, "user_id" => $this->user->id]));
     Redis::publish('colorme-channel', json_encode($publish_data));
     return $this->respond($comment);
 }
Ejemplo n.º 15
0
 public function topic(Request $request)
 {
     $topic = new Topic();
     $topic->name = $request->name;
     $topic->description = $request->description;
     $image_name = uploadFileToS3($request, 'avatar', 300, $topic->avatar_url);
     if ($image_name != null) {
         $topic->avatar_name = $image_name;
         $topic->avatar_url = $this->s3_url . $image_name;
     }
     $topic->class_id = $request->class_id;
     $topic->author_id = $this->user->id;
     $topic->deadline = $request->deadline;
     $topic->save();
     $class = StudyClass::find($request->class_id);
     foreach ($class->registers as $register) {
         $notification = new Notification();
         $notification->actor_id = $this->user->id;
         $notification->product_id = $topic->id;
         $notification->receiver_id = $register->user->id;
         $notification->type = 5;
         $notification->save();
         $data = array("message" => "Lớp " . $class->name . ": " . $this->user->name . " vừa tạo một topic mới ", "link" => url('group/class/' . $request->class_id . '#/topic/' . $topic->id), 'created_at' => format_date_full_option($notification->created_at), "receiver_id" => $notification->receiver_id);
         $publish_data = array("event" => "notification", "data" => $data);
         Redis::publish('colorme-channel', json_encode($publish_data));
     }
     return response()->json($topic, 200);
 }