Esempio n. 1
0
 public function update($id)
 {
     $data = Input::all();
     $avatar = Input::file('avatar');
     if (FEUsersHelper::isCurrentUser($id)) {
         $validator = FEUsersHelper::validateUpdateInfo();
         if ($validator->fails()) {
             $messages = $validator->messages();
             $errors = json_encode($messages);
             echo $errors;
         } else {
             $user = Users::where('account', $data['account'])->first();
             $user['fullname'] = $data['fullname'];
             $user['email'] = $data['email'];
             $user['phone'] = $data['phone'];
             $user['address'] = $data['address'];
             $user['about'] = $data['about'];
             if ($avatar) {
                 $upload_avatar_folder = 'avatar/' . $user->account . "/";
                 $name = $avatar->getFilename() . uniqid() . "." . $avatar->getClientOriginalExtension();
                 $avatar->move(public_path() . "/" . $upload_avatar_folder, $name);
                 $user->avatar = 'public/' . $upload_avatar_folder . $name;
             }
             $user->save();
             Session::flush('user');
             Session::put('user', $user);
             echo json_encode('success');
         }
     } else {
         echo json_encode('fail');
     }
     //        return false;
 }
 public function store()
 {
     if (FEUsersHelper::isLogged()) {
         $current_user_id = Session::get('user')['id'];
         $r_user_id = Input::get('r_user_id');
         $conversations = Conversation::where(function ($query) use($current_user_id, $r_user_id) {
             $query->where('user1_id', '=', $current_user_id)->where('user2_id', '=', $r_user_id);
         })->orWhere(function ($query) use($current_user_id, $r_user_id) {
             $query->where('user1_id', '=', $r_user_id)->where('user2_id', '=', $current_user_id);
         })->orderBy('updated_at', 'DESC')->get();
         $message = new Message();
         if ($conversations->count() > 0) {
             $conversation = $conversations->first();
             $message->content = Input::get('content');
             $message->s_user_id = $current_user_id;
             $message->conversation_id = $conversation->id;
             $message->save();
             $conversation->updated_at = date('Y-m-d H:m:s');
             $conversation->save();
             return Redirect::to('message/' . $conversation->id);
         } else {
             $conversation = new Conversation();
             $conversation->user1_id = $current_user_id;
             $conversation->user2_id = Input::get('r_user_id');
             $conversation->save();
             $message->content = Input::get('content');
             $message->s_user_id = $current_user_id;
             $message->conversation_id = $conversation->id;
             $message->save();
             return Redirect::to('message/' . $conversation->id);
         }
     }
     return Redirect::to('/');
 }
Esempio n. 3
0
 public function destroy($id)
 {
     $like = Like::find($id);
     if (FEUsersHelper::isCurrentUser($like['user_id'])) {
         $like->is_deleted = 1;
         $like->save();
         echo 'success';
     } else {
         echo 'fail';
     }
 }
 public function update($id)
 {
     $follow = Follow::find($id);
     if (FEUsersHelper::isCurrentUser($follow->follower->id)) {
         $follow->is_deleted = 1;
         $follow->save();
         echo 'true';
     } else {
         echo 'false';
     }
 }
Esempio n. 5
0
 public function destroy($id)
 {
     $post = Post::find($id);
     if ($post && FEUsersHelper::isCurrentUser($post->user->id)) {
         FELikesHelper::delete($post->getEntry()->id);
         FEEntriesHelper::delete($post->id, 1);
         $post->delete();
         echo 'true';
     } else {
         echo 'false';
     }
 }
Esempio n. 6
0
 private function getViewProfileDatas($user_id)
 {
     $privacy = Privacy::where('name', "Công khai")->get()->first();
     $datas = array();
     if (FEUsersHelper::isCurrentUser($user_id)) {
         $entries = Entry::where('user_id', $user_id)->orderBy('updated_at', 'DESC')->paginate($this->entries_per_page);
         $left_albums = Album::where('user_id', $user_id)->orderBy('updated_at', 'DESC')->get();
     } else {
         $entries = Entry::where('user_id', $user_id)->where('privacy', $privacy->id)->orderBy('updated_at', 'DESC')->paginate($this->entries_per_page);
         $left_albums = Album::where('user_id', $user_id)->where('privacy', 1)->orderBy('updated_at', 'DESC')->get();
     }
     return array("entries" => $entries, "left_albums" => $left_albums);
 }
Esempio n. 7
0
 public function update($id)
 {
     $blog = Blog::find($id);
     if (FEUsersHelper::isCurrentUser($blog->user->id)) {
         $blog->title = Input::get('title');
         $blog->content = Input::get('content');
         $blog->privacy = Input::get('privacy');
         $blog->save();
         FEEntriesHelper::updatePrivacy($blog->id, 2, $blog->privacy);
         return Redirect::back();
     } else {
         return Redirect::to('/');
     }
 }
Esempio n. 8
0
 public function index()
 {
     $user_id = Input::get('user_id');
     $user = User::find($user_id);
     if ($user) {
         if (FEUsersHelper::isCurrentUser($user->id)) {
             $images_d = Image::where('user_id', '=', $user->id);
         } else {
             $album_id = Album::where('user_id', '=', $user->id)->where('privacy', PrivaciesHelper::getId("Công khai"))->select('id')->get();
             $images_d = Image::where('user_id', '=', $user->id)->whereIn('album_id', $album_id->fetch('id')->toArray());
         }
         return View::make('frontend/photos/images/index')->with('user', $user)->with('images', $images_d->paginate($this->image_per_page));
     } else {
         return Redirect::to('/');
     }
 }
Esempio n. 9
0
 public function store()
 {
     $data = Input::all();
     $validator = FEUsersHelper::validateLoginInfo();
     if ($validator->fails()) {
         $messages = $validator->messages();
         echo json_encode($messages);
     } else {
         $user = Users::where('account', $data['account'])->get()->first();
         if (!$user) {
             echo "fail: Not exists user";
         } else {
             $user = Users::where('account', $data['account'])->where('password', md5($data['password']))->first();
             if (!$user) {
                 echo "fail: incorrect password";
             } else {
                 Session::put('user', $user);
                 echo "success";
             }
         }
     }
 }
Esempio n. 10
0
 public static function isCurrentUser($id)
 {
     if (FEUsersHelper::isLogged()) {
         if ($id == Session::get('current_user')) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Esempio n. 11
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     $user = User::find($id);
     foreach ($user->products as $product) {
         $product->delete();
     }
     if (FEUsersHelper::isCurrentUser($id)) {
         Session::flush('current_user');
     }
     $user->delete();
     Session::flash('status', true);
     Session::flash('messages', array('Đã xóa user'));
     return Redirect::route('admin.user.index');
 }
Esempio n. 12
0
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::resource('user', 'FEUsersController');
Route::get('', 'FEProductsController@index');
Route::get('/', 'FEProductsController@index');
Route::get('signup', 'FEUsersController@create');
Route::post('login', 'SessionController@store');
Route::get('logout', 'SessionController@delete');
Route::resource('category', 'FECategoriesController');
Route::resource('product', 'FEProductsController');
Route::resource('exchange', 'FEExchangesController');
Route::filter('checkAdmin', function () {
    if (!FEUsersHelper::isAdmin()) {
        $messages = array();
        $status = false;
        $messages[] = "Bạn không có quyền vào trang này";
        Session::flash('status', $status);
        Session::flash('messages', $messages);
        return Redirect::to('/');
    }
});
Route::group(array('prefix' => 'admin', 'before' => 'checkAdmin'), function () {
    Route::get('/', 'BEUsersController@index');
    Route::resource('category', 'BECategoriesController');
    Route::resource('user', 'BEUsersController');
    Route::resource('location', 'BELocationsController');
    Route::resource('product', 'BEProductsController');
});
Esempio n. 13
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     if (!FEUsersHelper::validateUpdateInfo()) {
         Session::flash('update_status', false);
         return Redirect::to('user/' . Session::get('current_user') . '/edit');
     } else {
         if (!FEUsersHelper::isExistedEmail()) {
             $user = FEUsersHelper::updateUser($id);
             if ($user) {
                 Session::flash('update_status', true);
                 Session::set("current_user", $user->id);
             }
         }
         return Redirect::to('user/' . Session::get('current_user') . '/edit');
     }
 }
Esempio n. 14
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $exchange = Exchange::find($id);
     $respone = Input::get('respone');
     if (FEUsersHelper::isCurrentUser($exchange->r_user_id && $respone)) {
         if ($respone == 'Đồng ý') {
             Session::flash('messages', array('Đã xác nhận trao đổi'));
             $exchange->status = 1;
         } elseif ($respone == 'Xóa') {
             Session::flash('messages', array('Đã hủy yêu cầu trao đổi'));
             $exchange->status = -1;
         }
         $exchange->save();
         Session::flash('status', true);
         return Redirect::to('exchange?user_id=' . $exchange->r_user_id . '&action=receive');
     } else {
         return Redirect::to('/');
     }
 }
Esempio n. 15
0
 public function update($id)
 {
     $album = Album::find($id);
     if (FEUsersHelper::isCurrentUser($album->id)) {
         $album->title = Input::get('title');
         $album->privacy = Input::get('privacy');
         $album->save();
         FEEntriesHelper::updatePrivacy($album->id, 2, Input::get('privacy'));
     }
     return Redirect::back();
 }
Esempio n. 16
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $product = Product::find($id);
     if (FEUsersHelper::isCurrentUser($product->user->id)) {
         $product->delete();
         Session::flash('status', true);
         Session::flash('messages', array('Đã xóa'));
     }
     return Redirect::to('/');
 }