lasthourcloud/app/Http/Controllers/Webhook/Waitlist.php

67 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\Webhook;
use App\Http\Controllers\Controller;
use App\Models\Waitlist as ModelsWaitlist;
use Exception;
use Illuminate\Http\Request;
class Waitlist extends Controller
{
public function confirm(Request $request)
{
$email = request()->get('email');
$confirmation_code = request()->get('confirmation_code');
ray($email, $confirmation_code);
try {
$found = ModelsWaitlist::where('uuid', $confirmation_code)->where('email', $email)->first();
if ($found) {
2024-06-10 20:43:34 +00:00
if (! $found->verified) {
if ($found->created_at > now()->subMinutes(config('constants.waitlist.expiration'))) {
$found->verified = true;
$found->save();
2024-06-10 20:43:34 +00:00
send_internal_notification('Waitlist confirmed: '.$email);
return 'Thank you for confirming your email address. We will notify you when you are next in line.';
} else {
$found->delete();
2024-06-10 20:43:34 +00:00
send_internal_notification('Waitlist expired: '.$email);
return 'Your confirmation code has expired. Please sign up again.';
}
}
}
2024-06-10 20:43:34 +00:00
return redirect()->route('dashboard');
} catch (Exception $e) {
2024-06-10 20:43:34 +00:00
send_internal_notification('Waitlist confirmation failed: '.$e->getMessage());
ray($e->getMessage());
2024-06-10 20:43:34 +00:00
return redirect()->route('dashboard');
}
}
2024-06-10 20:43:34 +00:00
public function cancel(Request $request)
{
$email = request()->get('email');
$confirmation_code = request()->get('confirmation_code');
try {
$found = ModelsWaitlist::where('uuid', $confirmation_code)->where('email', $email)->first();
2024-06-10 20:43:34 +00:00
if ($found && ! $found->verified) {
$found->delete();
2024-06-10 20:43:34 +00:00
send_internal_notification('Waitlist cancelled: '.$email);
return 'Your email address has been removed from the waitlist.';
}
2024-06-10 20:43:34 +00:00
return redirect()->route('dashboard');
} catch (Exception $e) {
2024-06-10 20:43:34 +00:00
send_internal_notification('Waitlist cancellation failed: '.$e->getMessage());
ray($e->getMessage());
2024-06-10 20:43:34 +00:00
return redirect()->route('dashboard');
}
}
}