public function storeForBan($id, Request $request)
 {
     $ban = Ban::findOrFail($id);
     $comment = \Input::get('body');
     if ($comment == '') {
         return \Redirect::back();
     }
     if ($request->user()->muted) {
         return \Redirect::back()->with('error', 'You are muted.');
     }
     $ban->comments()->create(['body' => $comment, 'user_id' => Auth::user()->id]);
     // Create notification
     $not = new Notification();
     $not->from($request->user())->withType('UserCommentOnBan')->withSubject('A comment is done on ban')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has commented on a ban " . link_to_route('bans.show', '#' . $ban->id, $ban->id))->withStream(true)->regarding($ban)->deliver();
     return \Redirect::back()->with('success', 'Success! Comment posted for the ban.');
 }
示例#2
0
 public function deleteBan($id)
 {
     $ban = Ban::findOrFail($id);
     $ban->delete();
     flash()->info('Postać o ID <b>' . $id . '</b> została odbanowana!');
     return redirect('/admin/ban');
 }
示例#3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @param InputRequest $request
  * @return Response
  */
 public function update($id, InputRequest $request)
 {
     if (!$request->user()->isAdmin()) {
         return redirect()->home()->with('error', "Not authorized");
     }
     $validator = \Validator::make($request->all(), ['status' => 'required|in:0,1']);
     if ($validator->fails()) {
         return \Redirect::back()->with('errors', $validator->errors())->withInput();
     }
     $ban = Ban::findOrFail($id);
     $prev_status = $ban->status;
     $status = $request->status;
     $reason = $request->reason == "" ? null : $request->reason;
     $banned_till = $request->banned_till;
     $banned_till = $banned_till == "" ? null : Carbon::parse($banned_till);
     // If its a unban work then banned till will be set to now.
     if ($status == 0 && $prev_status == 1) {
         $banned_till = Carbon::now();
     } else {
         if ($status == 1 && $prev_status == 0 && $banned_till != null && $banned_till <= Carbon::now()) {
             $banned_till = null;
         } else {
             if ($status == 0 && $prev_status == 0) {
                 if ($banned_till >= Carbon::now()) {
                     return redirect()->back()->with('error', 'Ban Till cannot me in future if status is "Unbanned".')->withInput();
                 } else {
                     if ($banned_till == "" || $banned_till == null) {
                         $banned_till = $ban->banned_till;
                     }
                 }
             }
         }
     }
     $ban->reason = $reason;
     $ban->status = $status;
     $ban->banned_till = $banned_till;
     $ban->updated_by = $request->user()->username;
     $ban->updated_by_site = true;
     $ban->save();
     // Create notification
     $not = new Notification();
     $not->from($request->user())->withType('BanUpdated')->withSubject('A ban is updated')->withBody(link_to_route('user.show', $request->user()->displayName(), $request->user()->username) . " has updated the ban " . link_to_route('bans.show', '#' . $ban->id, $ban->id) . " with IP <b>" . $ban->ipAddrWithMask() . "</b> <img src='" . $ban->countryImage() . "' class='tooltipster img' title='" . $ban->countryName() . "'>")->withStream(true)->regarding($ban)->deliver();
     if ($status == 0 && $prev_status == 1) {
         $ban->tellServerToRemove();
     } else {
         if ($status == 1 && $prev_status == 0) {
             $ban->tellServerToAdd();
         }
     }
     return redirect()->route('bans.show', $ban->id)->with('success', 'Ban has need updated!');
 }