pixelfed/app/Http/Controllers/ContactController.php

65 lines
1.8 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;
use App\Rules\MaxMultiLine;
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', new MaxMultiLine('500')],
2019-06-06 04:31:25 +00:00
'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;
2020-02-23 04:07:59 +00:00
$contact->response = '';
2019-06-07 03:13:52 +00:00
$contact->save();
ContactPipeline::dispatch($contact);
2019-06-19 00:49:24 +00:00
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
}
2024-10-10 08:03:20 +00:00
public function showAdminResponse(Request $request, $id)
{
abort_if(!$request->user(), 404);
$uid = $request->user()->id;
$contact = Contact::whereUserId($uid)
->whereNotNull('response')
->whereNotNull('responded_at')
->findOrFail($id);
return view('site.contact.admin-response', compact('contact'));
}
2019-06-06 04:31:25 +00:00
}