/**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create(Request $request)
 {
     $friend_id = $request->input("id");
     $result = User::getUserById($friend_id);
     $user_id = Auth::user()->user_id;
     $pusher = App::make('pusher');
     $pusher->trigger(strval($friend_id), 'onShowChatBox', ['user' => Auth::user()]);
     $messages = new Message();
     $result["message"] = $messages->getConversation($user_id, $friend_id, 5);
     return $result;
 }
예제 #2
0
 /**
  * Edit profile
  *
  * @param Request $request
  * @return $this|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function edit(Request $request)
 {
     $user = User::getUserById(Auth::user()->id);
     if ($request->isMethod('post')) {
         $rules = ['first_name' => 'required', 'last_name' => 'required', 'position' => 'required', 'phone' => 'phone:AM', 'username' => 'required|unique:users,username,' . $user->id, 'email' => 'required|email|unique:users,email,' . $user->id, 'pass' => 'min:6|max:12', 'pass_confirmation' => 'min:6|max:12|same:pass', 'image' => 'mimes:jpeg,jpg,png'];
         Validator::make($request->all(), $rules)->validate();
         $user->first_name = $request->input('first_name');
         $user->last_name = $request->input('last_name');
         $user->position = $request->input('position');
         if ($request->has('phone')) {
             $user->phone = $request->input('phone');
         }
         if (!empty($request->file("image"))) {
             if (!empty($user->image)) {
                 if (Storage::exists('uploads/' . $user->image)) {
                     Storage::delete('uploads/' . $user->image);
                 }
             }
             $generated_string = str_random(32);
             $file = $request->file("image")->store('uploads');
             $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
             Storage::move($file, 'uploads/' . $new_file);
             $img = Image::make($request->file('image'));
             $img->crop(200, 200);
             $img->save(storage_path('app/public/uploads/' . $new_file));
             $user->image = $new_file;
         }
         $user->username = $request->input('username');
         $user->email = $request->input('email');
         $user->notification = $request->has('notification');
         if ($request->has('pass')) {
             $user->password = Hash::make($request->input('pass'));
         }
         $user->save();
         return redirect('/');
     } else {
         return view('site.user.edit', compact('user'));
     }
 }
예제 #3
0
 public function getUserById($id)
 {
     return User::getUserById($id);
 }
예제 #4
0
 /**
  * User logout
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function logout()
 {
     $user = User::getUserById(Auth::user()->id);
     $user->online = 0;
     $user->save();
     Auth::logout();
     return redirect()->route('home');
 }
예제 #5
0
 public function getUserById($id)
 {
     return $this->_userModel->getUserById($id);
 }
 public function __toString()
 {
     // TODO: Implement __toString() method.
     //Form: {{username}} {{action}} {{object}}
     //Nhuan likes your post
     //Tung follow you
     $noti = "";
     $action = "";
     $username = "";
     $type = "";
     if ($this["type"] == FOLLOW) {
         $action = " follow ";
         if ($this["objectType"] == USER) {
             $type = " you ";
         } else {
             $board_title = Board::getBoardById($this->objectID)["board_title"];
             $type = " your board " . ' ' . $board_title;
         }
     } else {
         $type = "your post ";
         if ($this["type"] == LIKE) {
             $action = " liked ";
         } else {
             if ($this["type"] == COMMENT) {
                 $action = " comment on ";
             } else {
                 if ($this["type"] == PIN) {
                     $action = " pinned ";
                 }
             }
         }
     }
     if (isset($this["sender_id"])) {
         $username = User::getUserById($this["sender_id"])["name"];
     } else {
         $username = $this["sender_string"];
     }
     $noti = $username . $action . $type;
     return $noti;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //
     $user = User::getUserById($id);
     $user["name"] = $request->input("name");
     $user["description"] = $request->input("description");
     $user["username"] = $request->input('username');
     $user["email"] = $request->input('email');
     if ($request->input("avatar_link") != null) {
         $user["avatar_link"] = $request->input("avatar_link");
     }
     $result = $user->save();
     return response()->json(["result" => $result]);
 }
예제 #8
0
 /**
  * Delete user
  *
  * @param Request $request
  * @param int $id
  * @return \Illuminate\Http\RedirectResponse
  */
 public function delete(Request $request, $id = 0)
 {
     if ($request->isMethod('post')) {
         foreach ($request->input('users') as $user) {
             $user = User::getUserById($user);
             if (!empty($user)) {
                 if (!empty($user->image)) {
                     if (Storage::exists('uploads/' . $user->image)) {
                         Storage::delete('uploads/' . $user->image);
                     }
                 }
                 $user->delete();
             }
         }
     } else {
         $user = User::getUserById($id);
         if (!empty($user)) {
             if (!empty($user->image)) {
                 if (Storage::exists('uploads/' . $user->image)) {
                     Storage::delete('uploads/' . $user->image);
                 }
             }
             $user->delete();
         }
         return redirect()->back();
     }
 }