forked from mirror/pixelfed
Update ReportController, handle json reports
This commit is contained in:
parent
2cf85394b3
commit
5206b09627
|
@ -86,11 +86,11 @@ class ReportController extends Controller
|
||||||
public function formStore(Request $request)
|
public function formStore(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'report' => 'required|alpha_dash',
|
'report' => 'required|alpha_dash',
|
||||||
'type' => 'required|alpha_dash',
|
'type' => 'required|alpha_dash',
|
||||||
'id' => 'required|integer|min:1',
|
'id' => 'required|integer|min:1',
|
||||||
'msg' => 'nullable|string|max:150',
|
'msg' => 'nullable|string|max:150',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$profile = Auth::user()->profile;
|
$profile = Auth::user()->profile;
|
||||||
$reportType = $request->input('report');
|
$reportType = $request->input('report');
|
||||||
|
@ -113,7 +113,11 @@ class ReportController extends Controller
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!in_array($reportType, $types)) {
|
if (!in_array($reportType, $types)) {
|
||||||
return redirect('/timeline')->with('error', 'Invalid report type');
|
if($request->wantsJson()) {
|
||||||
|
return abort(400, 'Invalid report type');
|
||||||
|
} else {
|
||||||
|
return redirect('/timeline')->with('error', 'Invalid report type');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($object_type) {
|
switch ($object_type) {
|
||||||
|
@ -127,16 +131,28 @@ class ReportController extends Controller
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return redirect('/timeline')->with('error', 'Invalid report type');
|
if($request->wantsJson()) {
|
||||||
|
return abort(400, 'Invalid report type');
|
||||||
|
} else {
|
||||||
|
return redirect('/timeline')->with('error', 'Invalid report type');
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($exists !== 0) {
|
if ($exists !== 0) {
|
||||||
return redirect('/timeline')->with('error', 'You have already reported this!');
|
if($request->wantsJson()) {
|
||||||
|
return response()->json(200);
|
||||||
|
} else {
|
||||||
|
return redirect('/timeline')->with('error', 'You have already reported this!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($object->profile_id == $profile->id) {
|
if ($object->profile_id == $profile->id) {
|
||||||
return redirect('/timeline')->with('error', 'You cannot report your own content!');
|
if($request->wantsJson()) {
|
||||||
|
return response()->json(200);
|
||||||
|
} else {
|
||||||
|
return redirect('/timeline')->with('error', 'You cannot report your own content!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$report = new Report();
|
$report = new Report();
|
||||||
|
@ -149,6 +165,10 @@ class ReportController extends Controller
|
||||||
$report->message = e($request->input('msg'));
|
$report->message = e($request->input('msg'));
|
||||||
$report->save();
|
$report->save();
|
||||||
|
|
||||||
return redirect('/timeline')->with('status', 'Report successfully sent!');
|
if($request->wantsJson()) {
|
||||||
|
return response()->json(200);
|
||||||
|
} else {
|
||||||
|
return redirect('/timeline')->with('status', 'Report successfully sent!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue