flexisip-account-manager/flexiapi/app/Http/Controllers/Api/AuthTokenController.php
Timothée Jaussoin 354830da7e QRCode based authentication
Add routes, model and controller for AuthToken
Create auth_tokens table
Allow auth_token to be used for provisioning
Reorganize the API
Update the dependencies
2022-07-12 15:14:46 +02:00

34 lines
720 B
PHP

<?php
namespace App\Http\Controllers\Api;
use App\AuthToken;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class AuthTokenController extends Controller
{
public function store()
{
$authToken = new AuthToken;
$authToken->token = Str::random(32);
$authToken->save();
return $authToken;
}
public function attach(Request $request, string $token)
{
$authToken = AuthToken::where('token', $token)->valid()->firstOrFail();
if (!$authToken->account_id) {
$authToken->account_id = $request->user()->id;
$authToken->save();
return;
}
abort(404);
}
}