mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 10:08:05 +00:00
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
34 lines
720 B
PHP
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);
|
|
}
|
|
}
|