Skip to content

Commit

Permalink
Add regenerate license key button
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Nov 29, 2024
1 parent 7d2de19 commit 6594fe0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
24 changes: 24 additions & 0 deletions app/Http/Controllers/RegenerateLicenseKeyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Controllers;

use App\Domain\Shop\Models\License;
use Illuminate\Support\Str;

class RegenerateLicenseKeyController
{
public function __invoke(License $license)
{
if (! $license->isAssignedTo(current_user())) {
abort(403, "License {$license->id} is not assigned to user id" . current_user()->id);
}

$license->update([
'key' => Str::random(64),
]);

flash()->success('License key regenerated.');

return redirect()->back();
}
}
15 changes: 10 additions & 5 deletions resources/views/front/profile/purchases.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ class="fa-secondary"
class="fa-primary"
fill="currentColor"
d="M96 392V96H24a24 24 0 0 0-24 24v368a24 24 0 0 0 24 24h272a24 24 0 0 0 24-24v-40H152a56.06 56.06 0 0 1-56-56zM441 73L375 7a24 24 0 0 0-17-7h-6v96h96v-6.06A24 24 0 0 0 441 73z"></path></g></svg></span></code>
<form
x-data
@submit.prevent="if (confirm('Are you sure you want to regenerate this license key?')) $el.submit()"
class="mt-2"
action="{{ route('regenerate-key', $license) }}"
method="POST"
>
@csrf
<button type="submit" class="underline">Regenerate key</button>
</form>
</div>
</div>

Expand Down Expand Up @@ -212,11 +222,6 @@ class="px-6 flex justify-between items-center text-xs py-4 border-b border-gray-
</div>
</section>

@once
@push('scripts')
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
@endpush
@endonce
@push('scripts')
<script type="text/javascript">
function copyLicense(element, licenseKey) {
Expand Down
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Http\Controllers\DownloadPurchasableController;
use App\Http\Controllers\DownloadRayController;
use App\Http\Controllers\MusicController;
use App\Http\Controllers\RegenerateLicenseKeyController;
use App\Http\Controllers\ShowReleaseNotesController;
use App\Http\Controllers\GitHubSocialiteController;
use App\Http\Controllers\GuidelinesController;
Expand Down Expand Up @@ -134,6 +135,7 @@
Route::get('invoices', InvoicesController::class)->name('invoices');

Route::get('download-latest-version-for-expired-license/{license}/{repo}', DownloadLatestReleaseForExpiredLicenseController::class)->name('downloadLatestRelease');
Route::post('regenerate-key/{license}', RegenerateLicenseKeyController::class)->name('regenerate-key');
});

Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
Expand Down

0 comments on commit 6594fe0

Please sign in to comment.