2019-02-16 03:13:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Auth;
|
|
|
|
use App\UserInvite;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class UserInviteController extends Controller
|
|
|
|
{
|
|
|
|
public function create(Request $request)
|
|
|
|
{
|
2021-12-04 22:30:08 +00:00
|
|
|
abort_if(!config('pixelfed.user_invites.enabled'), 404);
|
2019-02-16 03:13:24 +00:00
|
|
|
abort_unless(Auth::check(), 403);
|
|
|
|
return view('settings.invites.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Request $request)
|
|
|
|
{
|
2021-12-04 22:30:08 +00:00
|
|
|
abort_if(!config('pixelfed.user_invites.enabled'), 404);
|
2019-02-16 03:13:24 +00:00
|
|
|
abort_unless(Auth::check(), 403);
|
|
|
|
$invites = UserInvite::whereUserId(Auth::id())->paginate(10);
|
|
|
|
$limit = config('pixelfed.user_invites.limit.total');
|
|
|
|
$used = UserInvite::whereUserId(Auth::id())->count();
|
|
|
|
return view('settings.invites.home', compact('invites', 'limit', 'used'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2021-12-04 22:30:08 +00:00
|
|
|
abort_if(!config('pixelfed.user_invites.enabled'), 404);
|
2019-02-16 03:13:24 +00:00
|
|
|
abort_unless(Auth::check(), 403);
|
|
|
|
$this->validate($request, [
|
|
|
|
'email' => 'required|email|unique:users|unique:user_invites',
|
|
|
|
'message' => 'nullable|string|max:500',
|
|
|
|
'tos' => 'required|accepted'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$invite = new UserInvite;
|
|
|
|
$invite->user_id = Auth::id();
|
|
|
|
$invite->profile_id = Auth::user()->profile->id;
|
|
|
|
$invite->email = $request->input('email');
|
|
|
|
$invite->message = $request->input('message');
|
|
|
|
$invite->key = (string) Str::uuid();
|
|
|
|
$invite->token = str_random(32);
|
|
|
|
$invite->save();
|
|
|
|
|
|
|
|
return redirect(route('settings.invites'));
|
|
|
|
}
|
|
|
|
}
|