2024-03-01 13:04:29 +00:00
|
|
|
<?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) {
|
2024-03-01 13:04:29 +00:00
|
|
|
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);
|
|
|
|
|
2024-03-01 13:04:29 +00:00
|
|
|
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);
|
|
|
|
|
2024-03-01 13:04:29 +00:00
|
|
|
return 'Your confirmation code has expired. Please sign up again.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-01 13:04:29 +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());
|
2024-03-01 13:04:29 +00:00
|
|
|
ray($e->getMessage());
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-01 13:04:29 +00:00
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-01 13:04:29 +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) {
|
2024-03-01 13:04:29 +00:00
|
|
|
$found->delete();
|
2024-06-10 20:43:34 +00:00
|
|
|
send_internal_notification('Waitlist cancelled: '.$email);
|
|
|
|
|
2024-03-01 13:04:29 +00:00
|
|
|
return 'Your email address has been removed from the waitlist.';
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-01 13:04:29 +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());
|
2024-03-01 13:04:29 +00:00
|
|
|
ray($e->getMessage());
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-01 13:04:29 +00:00
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|