1
0
Fork 0
pixelfed/app/Http/Controllers/ContactController.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2019-06-06 04:31:25 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
2019-06-07 03:13:52 +00:00
use App\Contact;
2019-06-19 00:49:24 +00:00
use App\Jobs\ContactPipeline\ContactPipeline;
2019-06-06 04:31:25 +00:00
class ContactController extends Controller
{
public function show(Request $request)
{
2019-06-19 00:49:24 +00:00
abort_if(!config('instance.email') && !config('instance.contact.enabled'), 404);
2019-06-06 04:31:25 +00:00
return view('site.contact');
}
public function store(Request $request)
{
2019-06-18 20:17:43 +00:00
abort_if(!config('instance.contact.enabled'), 404);
2019-06-06 04:31:25 +00:00
abort_if(!Auth::check(), 403);
$this->validate($request, [
'message' => 'required|string|min:5|max:500',
'request_response' => 'string|max:3'
]);
$message = $request->input('message');
$request_response = $request->input('request_response') == 'on' ? true : false;
$user = Auth::user();
2019-06-07 03:13:52 +00:00
2019-06-18 20:17:43 +00:00
$max = config('instance.contact.max_per_day');
2019-06-07 03:13:52 +00:00
$contact = Contact::whereUserId($user->id)
2019-06-18 20:17:43 +00:00
->whereDate('created_at', '>', now()->subDays($max))
2019-06-07 03:13:52 +00:00
->count();
2019-06-19 01:58:57 +00:00
if($contact >= $max) {
2019-06-07 03:13:52 +00:00
return redirect()->back()->with('error', 'You have recently sent a message. Please try again later.');
}
$contact = new Contact;
$contact->user_id = $user->id;
$contact->response_requested = $request_response;
$contact->message = $message;
$contact->save();
2019-06-19 00:49:24 +00:00
ContactPipeline::dispatchNow($contact);
2019-06-07 03:13:52 +00:00
return redirect()->back()->with('status', 'Success - Your message has been sent to admins.');
2019-06-06 04:31:25 +00:00
}
}