Esempio n. 1
0
 public function destroy($id)
 {
     Cache::flush();
     if (Auth::check()) {
         $mp3 = MP3::find($id);
         if (Auth::user()->id == $mp3->user_id || User::is_admin()) {
             if ($mp3) {
                 Vote::whereObj('MP3')->whereObjId($mp3->id)->whereUserId(Auth::user()->id)->delete();
                 $mp3->delete();
                 File::delete(Config::get('site.mp3_upload_path') . '/' . $mp3->mp3name);
                 File::delete(Config::get('site.image_upload_path') . '/' . $mp3->image);
                 File::delete(Config::get('site.image_upload_path') . '/thumbs/' . $mp3->image);
                 File::delete(Config::get('site.image_upload_path') . '/tiny/' . $mp3->image);
                 File::delete(Config::get('site.image_upload_path') . '/show/' . $mp3->image);
                 if (Auth::user()->is_admin()) {
                     return Redirect::to('/admin/mp3');
                 }
                 return Redirect::to('/mp3');
             } else {
                 return Redirect::to('/mp3')->withMessage('Nou regrèt men nou pa reyisi efase mizik la.');
             }
         }
     }
     return Redirect::to('/mp3')->withMessage('Ou pa gen dwa pou efase mizik la.');
 }
Esempio n. 2
0
 public function deleteUser($id = null)
 {
     $del = Input::get('del');
     if (!empty($id) && Auth::user()->is_admin()) {
         $admin = Auth::user();
         $user = User::find($id);
         $mp3s = $user->mp3s()->get();
         $mp4s = $user->mp4s()->get();
         foreach ($mp3s as $mp3) {
             $mp3->user_id = $admin->id;
             $mp3->save();
             Vote::whereObj('MP3')->whereObjId($mp3->id)->whereUserId($user->id)->delete();
         }
         foreach ($mp4s as $mp4) {
             $mp4->user_id = $admin->id;
             $mp4->save();
             Vote::whereObj('MP4')->whereObjId($mp4->id)->whereUserId($user->id)->delete();
         }
         $user->delete();
         return Redirect::back();
     }
     $user = Auth::user();
     $admin = User::whereAdmin(1)->first();
     $mp3s = $user->mp3s()->get();
     $mp4s = $user->mp4s()->get();
     foreach ($mp3s as $mp3) {
         Vote::whereObj('MP3')->whereObjId($mp3->id)->whereUserId($user->id)->delete();
         if ($del) {
             $mp3->delete();
             File::delete(Config::get('site.mp3_upload_path') . '/' . $mp3->mp3name);
             File::delete(Config::get('site.image_upload_path') . '/' . $mp3->image);
             File::delete(Config::get('site.image_upload_path') . '/thumbs/' . $mp3->image);
             File::delete(Config::get('site.image_upload_path') . '/tiny/' . $mp3->image);
         } else {
             $mp3->user_id = $admin->id;
             $mp3->save();
         }
     }
     foreach ($mp4s as $mp4) {
         Vote::whereObj('MP4')->whereObjId($mp4->id)->whereUserId($user->id)->delete();
         if ($del) {
             $mp4->delete();
         } else {
             $mp4->user_id = $admin->id;
             $mp4->save();
         }
     }
     Auth::logout();
     $user->delete();
     Cache::flush();
     $aff = '';
     if ($del) {
         $aff = 'Mizik ak Videyo ou yo efase tou avèk siskè. Ou ka <a href="/register">kreye yon nouvo kont</a> nenpòt lè ou vle.';
     }
     return Redirect::to('/')->withMessage('Kont ou an efase avèk sikè. ' . $aff);
 }