mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
controller refactoring part 10
This commit is contained in:
@@ -60,11 +60,11 @@
|
||||
"/chunks/profile.js": "/chunks/profile.js?id=41b536880e846017d2d0",
|
||||
"/chunks/profile~chunks/settings-password.js": "/chunks/profile~chunks/settings-password.js?id=fd25990d1ccec0294602",
|
||||
"/chunks/purchase-code.js": "/chunks/purchase-code.js?id=b35e751cdc1946a4fb60",
|
||||
"/chunks/settings.js": "/chunks/settings.js?id=b7d5d142d6e4cae354b0",
|
||||
"/chunks/settings.js": "/chunks/settings.js?id=7070921d97a2510445ac",
|
||||
"/chunks/settings-create-payment-methods.js": "/chunks/settings-create-payment-methods.js?id=0e818baec7f92c7fa542",
|
||||
"/chunks/settings-invoices.js": "/chunks/settings-invoices.js?id=eab2781e9935230c6971",
|
||||
"/chunks/settings-password.js": "/chunks/settings-password.js?id=b01b17b523e99064d8ca",
|
||||
"/chunks/settings-payment-methods.js": "/chunks/settings-payment-methods.js?id=1a1c7f6e9c2857ec941f",
|
||||
"/chunks/settings-password.js": "/chunks/settings-password.js?id=9258c6edb9815296b976",
|
||||
"/chunks/settings-payment-methods.js": "/chunks/settings-payment-methods.js?id=fc84aad90497e1ae99f9",
|
||||
"/chunks/settings-storage.js": "/chunks/settings-storage.js?id=682f4f690ac252a78a3a",
|
||||
"/chunks/settings-subscription.js": "/chunks/settings-subscription.js?id=4f1793d53633a2c4cc18",
|
||||
"/chunks/settings~chunks/settings-password.js": "/chunks/settings~chunks/settings-password.js?id=f5aaffe3aa073cb2ee19",
|
||||
@@ -78,7 +78,7 @@
|
||||
"/chunks/stripe-credentials.js": "/chunks/stripe-credentials.js?id=3beb031ba99961e8c51c",
|
||||
"/chunks/subscription-plans.js": "/chunks/subscription-plans.js?id=4ae406cdb5805d9c4a45",
|
||||
"/chunks/subscription-service.js": "/chunks/subscription-service.js?id=a09dc140a3914fb64a1a",
|
||||
"/chunks/upgrade-billing.js": "/chunks/upgrade-billing.js?id=0de6296ee18d466dca13",
|
||||
"/chunks/upgrade-billing.js": "/chunks/upgrade-billing.js?id=2ae7d7c13fee27b4edff",
|
||||
"/chunks/upgrade-billing~chunks/upgrade-plan.js": "/chunks/upgrade-billing~chunks/upgrade-plan.js?id=43888143d0a6afe67d7a",
|
||||
"/chunks/upgrade-plan.js": "/chunks/upgrade-plan.js?id=5979a154f760a992e617",
|
||||
"/chunks/user.js": "/chunks/user.js?id=41076be9126702330159",
|
||||
@@ -275,5 +275,9 @@
|
||||
"/chunks/platform.13a7c4eb981e304dd11c.hot-update.js": "/chunks/platform.13a7c4eb981e304dd11c.hot-update.js",
|
||||
"/chunks/platform.1dc9a86f8f195ad336c8.hot-update.js": "/chunks/platform.1dc9a86f8f195ad336c8.hot-update.js",
|
||||
"/chunks/platform.c72b7ed144ae27e09ac0.hot-update.js": "/chunks/platform.c72b7ed144ae27e09ac0.hot-update.js",
|
||||
"/chunks/homepage.e80d5d3c53decab802d5.hot-update.js": "/chunks/homepage.e80d5d3c53decab802d5.hot-update.js"
|
||||
"/chunks/homepage.e80d5d3c53decab802d5.hot-update.js": "/chunks/homepage.e80d5d3c53decab802d5.hot-update.js",
|
||||
"/chunks/settings-payment-methods.8681aa04995d55912730.hot-update.js": "/chunks/settings-payment-methods.8681aa04995d55912730.hot-update.js",
|
||||
"/chunks/upgrade-billing.8681aa04995d55912730.hot-update.js": "/chunks/upgrade-billing.8681aa04995d55912730.hot-update.js",
|
||||
"/chunks/settings.38169fdae69094598f31.hot-update.js": "/chunks/settings.38169fdae69094598f31.hot-update.js",
|
||||
"/chunks/settings-password.38169fdae69094598f31.hot-update.js": "/chunks/settings-password.38169fdae69094598f31.hot-update.js"
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ export default {
|
||||
this.isLoading = true
|
||||
|
||||
axios
|
||||
.post('/api/user/token/create', {
|
||||
.post('/api/user/tokens', {
|
||||
name: this.name
|
||||
})
|
||||
.then(response => {
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
})
|
||||
},
|
||||
deleteToken(id) {
|
||||
axios.delete(`/api/user/token/revoke/${id}`)
|
||||
axios.delete(`/api/user/tokens/${id}`)
|
||||
.then(() => {
|
||||
|
||||
this.tokens = this.tokens.filter(tokenItem => tokenItem.id !== id)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Users\Controllers\AccessTokenController;
|
||||
use App\Users\Controllers\AuthController;
|
||||
use App\Users\Controllers\AccountController;
|
||||
use Domain\Payments\Controllers\PaymentMethodsController;
|
||||
@@ -18,15 +19,15 @@ Route::post('/email/resend/verify', [AccountController::class, 'resend_verificat
|
||||
Route::group(['middleware' => ['auth:sanctum']], function () {
|
||||
// Account
|
||||
Route::patch('/relationships/settings', [AccountController::class, 'update_user_settings']);
|
||||
Route::delete('/token/revoke/{token}', [AccountController::class, 'revoke_token']);
|
||||
Route::post('/token/create', [AccountController::class, 'create_token']);
|
||||
Route::post('/password', [AccountController::class, 'change_password']);
|
||||
Route::get('/subscription', [SubscriptionController::class, 'show']);
|
||||
Route::get('/tokens', [AccountController::class, 'tokens']);
|
||||
Route::get('/invoices', [AccountController::class, 'invoices']);
|
||||
Route::get('/storage', [AccountController::class, 'storage']);
|
||||
Route::get('/', [AccountController::class, 'user']);
|
||||
|
||||
// User Access Token
|
||||
Route::apiResource('/tokens', AccessTokenController::class);
|
||||
|
||||
// Payment cards
|
||||
Route::apiResource('/payment-cards', PaymentMethodsController::class);
|
||||
|
||||
|
||||
64
src/App/Users/Controllers/AccessTokenController.php
Normal file
64
src/App/Users/Controllers/AccessTokenController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Users\Controllers;
|
||||
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Users\Requests\UserCreateAccessTokenRequest;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Sanctum\PersonalAccessToken;
|
||||
|
||||
class AccessTokenController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get all user tokens
|
||||
*/
|
||||
public function index(): Response
|
||||
{
|
||||
return response(
|
||||
Auth::user()->tokens()->get(), 200
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user tokens
|
||||
*/
|
||||
public function store(UserCreateAccessTokenRequest $request): Response
|
||||
{
|
||||
abort_if(is_demo_account('howdy@hi5ve.digital'), 201, [
|
||||
'name' => 'token',
|
||||
'token' => Str::random(40),
|
||||
'abilities' => '["*"]',
|
||||
'tokenable_id' => Str::uuid(),
|
||||
'updated_at' => now(),
|
||||
'created_at' => now(),
|
||||
'id' => Str::random(40),
|
||||
]);
|
||||
|
||||
$token = Auth::user()
|
||||
->createToken(
|
||||
$request->input('name')
|
||||
);
|
||||
|
||||
return response($token, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user token
|
||||
*/
|
||||
public function destroy(PersonalAccessToken $token): Response
|
||||
{
|
||||
abort_if(is_demo_account('howdy@hi5ve.digital'), 204, 'Deleted!');
|
||||
|
||||
if (Auth::id() !== $token->tokenable_id) {
|
||||
return response('Unauthorized', 401);
|
||||
}
|
||||
|
||||
$token->delete();
|
||||
|
||||
return response('Deleted!', 204);
|
||||
}
|
||||
}
|
||||
@@ -129,49 +129,6 @@ class AccountController extends Controller
|
||||
return response('Changed!', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user tokens
|
||||
*/
|
||||
public function tokens(): Response
|
||||
{
|
||||
return response(
|
||||
Auth::user()->tokens()->get(),
|
||||
200
|
||||
);
|
||||
}
|
||||
|
||||
public function create_token(UserCreateAccessTokenRequest $request): Response
|
||||
{
|
||||
// Check if is demo
|
||||
abort_if(is_demo_account('howdy@hi5ve.digital'), 201, [
|
||||
'name' => 'token',
|
||||
'token' => Str::random(40),
|
||||
'abilities' => '["*"]',
|
||||
'tokenable_id' => Str::uuid(),
|
||||
'updated_at' => now(),
|
||||
'created_at' => now(),
|
||||
'id' => Str::random(40),
|
||||
]);
|
||||
|
||||
$token = Auth::user()->createToken($request->input('name'));
|
||||
|
||||
return response($token, 201);
|
||||
}
|
||||
|
||||
public function revoke_token(PersonalAccessToken $token): Response
|
||||
{
|
||||
// Check if is demo
|
||||
abort_if(is_demo_account('howdy@hi5ve.digital'), 204, 'Deleted!');
|
||||
|
||||
if (Auth::id() !== $token->tokenable_id) {
|
||||
return response('Unauthorized', 401);
|
||||
}
|
||||
|
||||
$token->delete();
|
||||
|
||||
return response('Deleted!', 204);
|
||||
}
|
||||
|
||||
public function email_verification(string $id, Request $request): RedirectResponse | Response
|
||||
{
|
||||
if (! $request->hasValidSignature()) {
|
||||
|
||||
@@ -16,7 +16,7 @@ class StorePlansController extends Controller
|
||||
) {
|
||||
}
|
||||
|
||||
public function store_stripe_plans(
|
||||
public function __invoke(
|
||||
StoreStripePlansRequest $request
|
||||
): Response {
|
||||
foreach ($request->input('plans') as $plan) {
|
||||
|
||||
@@ -15,7 +15,7 @@ class StoreSubscriptionServiceCredentialsController extends Controller
|
||||
/**
|
||||
* Store and test stripe credentials
|
||||
*/
|
||||
public function store_stripe_credentials(
|
||||
public function __invoke(
|
||||
StoreStripeCredentialsRequest $request
|
||||
): Response {
|
||||
if (! app()->runningUnitTests()) {
|
||||
|
||||
@@ -18,7 +18,7 @@ class GetSetupIntentController extends Controller
|
||||
public StripeService $stripe,
|
||||
) {}
|
||||
|
||||
public function setup_intent(): Response
|
||||
public function __invoke(): Response
|
||||
{
|
||||
return response(
|
||||
$this->stripe->getSetupIntent(Auth::user()), 201
|
||||
|
||||
@@ -18,7 +18,7 @@ class PersonalAccessTokenTest extends TestCase
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/user/token/create', [
|
||||
->postJson('/api/user/tokens', [
|
||||
'name' => 'token',
|
||||
])
|
||||
->assertStatus(201);
|
||||
@@ -43,7 +43,7 @@ class PersonalAccessTokenTest extends TestCase
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->deleteJson("/api/user/token/revoke/$token_id")
|
||||
->deleteJson("/api/user/tokens/$token_id")
|
||||
->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseMissing('personal_access_tokens', [
|
||||
|
||||
Reference in New Issue
Block a user