31 lines
841 B
PHP
31 lines
841 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Participant;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ParticipantController extends Controller
|
|
{
|
|
public static function createFromToken(Request $request, string $id)
|
|
{
|
|
if ($request->input('password') !== 'password123') {
|
|
return response()->json(['message' => 'Unauthorized: Wrong password'], 401);
|
|
}
|
|
|
|
if(!Participant::where('user_id', $id)->exists()) {
|
|
$participant = Participant::create([
|
|
'user_id' => $id,
|
|
'token' => uniqid()
|
|
]);
|
|
|
|
return $participant->token;
|
|
}
|
|
else {
|
|
$participant = Participant::where('user_id', $id)->first();
|
|
return $participant->token;
|
|
}
|
|
}
|
|
}
|