Skip to content

Commit

Permalink
Merge pull request #351 from NizarBerjawi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
NizarBerjawi authored Aug 31, 2023
2 parents fa6c912 + 1ad781f commit 167d73e
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 73 deletions.
28 changes: 14 additions & 14 deletions app/Http/Controllers/Dashboard/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ public function index(Request $request)
]);
}

public function show(Request $request, $id)
public function show(Request $request, $uuid)
{
$token = $request->user()->tokens()->where('id', $id)->first();
$token = $request->user()->tokens()->where('uuid', $uuid)->first();

return view('admin.tokens.show', [
'token' => $token,
]);
}

public function edit(Request $request, $id)
public function edit(Request $request, $uuid)
{
$token = $request->user()->tokens()->where('id', $id)->first();
$token = $request->user()->tokens()->where('uuid', $uuid)->first();

return view('admin.tokens.edit', [
'token' => $token,
]);
}

public function update(TokenPutRequest $request, $id)
public function update(TokenPutRequest $request, $uuid)
{
$token = $request->user()->tokens()->where('id', $id)->first();
$token = $request->user()->tokens()->where('uuid', $uuid)->first();

$action = $request->get('action');

Expand All @@ -50,7 +50,7 @@ public function update(TokenPutRequest $request, $id)
$textToken = $newAccessToken->plainTextToken;

if (strpos($textToken, '|') !== false) {
[$id, $textToken] = explode('|', $textToken, 2);
[$uuid, $textToken] = explode('|', $textToken, 2);
}
}

Expand All @@ -61,7 +61,7 @@ public function update(TokenPutRequest $request, $id)
}

return redirect()
->route('admin.tokens.show', $id)
->route('admin.tokens.show', $uuid)
->with('textToken', $textToken ?? null);
}

Expand All @@ -82,24 +82,24 @@ public function store(TokenPostRequest $request)
$textToken = $token->plainTextToken;

if (strpos($textToken, '|') !== false) {
[$id, $textToken] = explode('|', $textToken, 2);
[$uuid, $textToken] = explode('|', $textToken, 2);
}

return redirect()->route('admin.tokens.show', $id)->with('textToken', $textToken);
return redirect()->route('admin.tokens.show', $uuid)->with('textToken', $textToken);
}

public function destroy(Request $request, $id)
public function destroy(Request $request, $uuid)
{
$request->user()->tokens()->where('id', $id)->delete();
$request->user()->tokens()->where('uuid', $uuid)->delete();

return redirect()->route('admin.tokens.index');
}

public function confirm(TokenConfirmRequest $request, $id)
public function confirm(TokenConfirmRequest $request, $uuid)
{
$action = $request->get('action');

$token = $request->user()->tokens()->where('id', $id)->first();
$token = $request->user()->tokens()->where('uuid', $uuid)->first();

return view("admin.tokens.$action", compact('action', 'token'));
}
Expand Down
38 changes: 38 additions & 0 deletions app/Models/Sanctum/PersonalAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,50 @@
namespace App\Models\Sanctum;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Laravel\Sanctum\NewAccessToken;
use Laravel\Sanctum\PersonalAccessToken as SanctumPersonalAccessToken;

class PersonalAccessToken extends SanctumPersonalAccessToken
{
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'uuid';

/**
* The "type" of the primary key ID.
*
* @var string
*/
protected $keyType = 'string';

/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;

/**
* Bootstrap the model and its traits.
*
* @return void
*/
protected static function boot()
{
parent::boot();

static::creating(function (Model $model) {
if (empty($model->{$model->getKeyName()})) {
$model->{$model->getKeyName()} = Str::uuid()->toString();
}
});
}

/**
* Regenerates the current access token.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->uuid();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/tokens/delete.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</article>

<form method="post" action="{{ route('admin.tokens.destroy', $token->id) }}">
<form method="post" action="{{ route('admin.tokens.destroy', $token->uuid) }}">
@csrf
@method('DELETE')

Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/tokens/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

<article class="message is-info">
<div class="message-body">
{!! __('tokens.edit', ['regenerateLink' => route('admin.tokens.confirm', ['id' => $token->id, 'action' => 'regenerate'])]) !!}
{!! __('tokens.edit', ['regenerateLink' => route('admin.tokens.confirm', ['uuid' => $token->uuid, 'action' => 'regenerate'])]) !!}
</div>
</article>
<form method="post" action="{{ route('admin.tokens.update', ['id' => $token->id, 'action' => 'update']) }}">
<form method="post" action="{{ route('admin.tokens.update', ['uuid' => $token->uuid, 'action' => 'update']) }}">
@method('PUT')
@csrf

Expand Down
6 changes: 3 additions & 3 deletions resources/views/admin/tokens/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<div class="is-flex is-justify-content-space-between">
<div>
<div class="title is-size-4">
<a href="{{ route('admin.tokens.show', $token->id) }}">{{ $token->name }}</a>
<a href="{{ route('admin.tokens.show', $token->uuid) }}">{{ $token->name }}</a>

<a href="{{ route('admin.tokens.confirm', ['id' => $token->id, 'action' => 'regenerate']) }}"
<a href="{{ route('admin.tokens.confirm', ['uuid' => $token->uuid, 'action' => 'regenerate']) }}"
title="Regenerate token">
<span class="icon is-clickable">
<i class="icon is-small" data-feather="refresh-cw"></i>
Expand All @@ -41,7 +41,7 @@
</div>

<div class="is-flex is-align-content-center is-flex-wrap-wrap">
<a href="{{ route('admin.tokens.confirm', ['id' => $token->id, 'action' => 'delete']) }}"
<a href="{{ route('admin.tokens.confirm', ['uuid' => $token->uuid, 'action' => 'delete']) }}"
class="button is-small is-danger is-light" title="Delete token">
<i class="icon is-small" data-feather="trash-2"></i>
</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/tokens/regenerate.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</article>

<form method="post" action="{{ route('admin.tokens.update', ['id' => $token->id, 'action' => $action]) }}">
<form method="post" action="{{ route('admin.tokens.update', ['uuid' => $token->uuid, 'action' => $action]) }}">
@csrf
@method('PUT')

Expand Down
6 changes: 3 additions & 3 deletions resources/views/admin/tokens/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
</div>
@else
<div class="buttons has-addons is-centered">
<a href="{{ route('admin.tokens.edit', ['id' => $token->id]) }}"
<a href="{{ route('admin.tokens.edit', ['uuid' => $token->uuid]) }}"
class="button has-text-primary is-normal is-responsive">
<i class="icon is-small" data-feather="edit"></i>

<span class="has-text-weight-bold">Edit</span>
</a>

<a href="{{ route('admin.tokens.confirm', ['id' => $token->id, 'action' => 'regenerate']) }}"
<a href="{{ route('admin.tokens.confirm', ['uuid' => $token->uuid, 'action' => 'regenerate']) }}"
class="button has-text-warning is-normal is-responsive">
<i class="icon is-small" data-feather="refresh-cw"></i>

<span>Regenerate</span>
</a>

<a href="{{ route('admin.tokens.confirm', ['id' => $token->id, 'action' => 'delete']) }}"
<a href="{{ route('admin.tokens.confirm', ['uuid' => $token->uuid, 'action' => 'delete']) }}"
class="button has-text-danger is-normal is-responsive">
<i class="icon is-small" data-feather="trash-2"></i>

Expand Down
4 changes: 0 additions & 4 deletions resources/views/layouts/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

<main>
<div class="container">
<section class="section mt-2">
@include('partials.tabs')
</section>

<section class="section">
<div class="columns">
<div class="column is-6 is-offset-3">
Expand Down
81 changes: 71 additions & 10 deletions resources/views/partials/navbar.blade.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,84 @@
<nav class="navbar">
<div class="navbar-brand">
@if (!request()->routeIs('home'))
<a class="navbar-item is-size-4" href={{ route('home') }}>
<span class="icon-text">
<span class="has-text-primary ">
<i class="icon is-medium is-clickable" data-feather="home"></i>
</span>
</span>
</a>
@endif

<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="mainNavbar">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="mainNavbar" class="navbar-menu">
<div class="navbar-start">
@if (!request()->routeIs('home'))
<a class="navbar-item is-size-4" href={{ route('home') }}>
<span class="icon-text">
<span class="has-text-primary ">
<i class="icon is-medium is-clickable" data-feather="arrow-left-circle"></i>
</span>
</span>
@if (Auth::check() && Route::is('admin.*'))
<div class="navbar-start">

<a href="{{ route('admin.tokens.index') }}" @class([
'is-active' => Route::is('admin.tokens*'),
'navbar-item',
'icon-text',
])>
<span>Tokens</span>
</a>
@endif
</div>

<a href="{{ route('admin.security.index') }}" @class([
'is-active' =>
Route::is('admin.security.*') ||
(isset($intended) && $intended === route('admin.security.index')),
'navbar-item',
'icon-text',
])>
<span>Security</span>
</a>

<a href="{{ route('admin.account.index') }}" @class([
'is-active' =>
Route::is('admin.account.*') ||
(isset($intended) &&
$intended ===
route('admin.account.confirm', [
'id' => request()->user()->id,
'action' => 'delete',
])),
'navbar-item',
'icon-text',
])>
<span>Account</span>
</a>

<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
API
</a>

<div class="navbar-dropdown">
<a href="{{ route('admin.api.gettingStarted') }}" @class([
'is-active' => Route::is('admin.api.gettingStarted'),
'navbar-item',
'icon-text',
])>
<span>Getting Started</span>
</a>

<a href="{{ route('admin.api.docs') }}" @class([
'is-active' => Route::is('admin.api.docs'),
'navbar-item',
'icon-text',
])>
<span>API Reference</span>
</a>
</div>
</div>
</div>
@endif

<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
Expand Down
29 changes: 0 additions & 29 deletions resources/views/partials/tabs.blade.php

This file was deleted.

14 changes: 9 additions & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
Route::middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
->prefix('user')
->group(function () {

Route::get('/gettingStarted', [WebController::class, 'gettingStarted'])->name('admin.api.gettingStarted');
Route::get('/documentation', [WebController::class, 'docs'])->name('admin.api.docs');

Route::get('/confirm-password', [SecurityController::class, 'confirm']);

Route::get('security', [SecurityController::class, 'index'])->name('admin.security.index');
Expand All @@ -54,11 +58,11 @@
->group(function () {
Route::get('/', [TokenController::class, 'index'])->name('admin.tokens.index');
Route::get('create', [TokenController::class, 'create'])->name('admin.tokens.create');
Route::get('{id}', [TokenController::class, 'show'])->name('admin.tokens.show');
Route::get('{id}/edit', [TokenController::class, 'edit'])->name('admin.tokens.edit');
Route::get('{uuid}', [TokenController::class, 'show'])->name('admin.tokens.show');
Route::get('{uuid}/edit', [TokenController::class, 'edit'])->name('admin.tokens.edit');
Route::post('/', [TokenController::class, 'store'])->name('admin.tokens.store');
Route::put('{id}', [TokenController::class, 'update'])->name('admin.tokens.update');
Route::delete('{id}', [TokenController::class, 'destroy'])->name('admin.tokens.destroy');
Route::get('{id}/confirm', [TokenController::class, 'confirm'])->name('admin.tokens.confirm');
Route::put('{uuid}', [TokenController::class, 'update'])->name('admin.tokens.update');
Route::delete('{uuid}', [TokenController::class, 'destroy'])->name('admin.tokens.destroy');
Route::get('{uuid}/confirm', [TokenController::class, 'confirm'])->name('admin.tokens.confirm');
});
});

0 comments on commit 167d73e

Please sign in to comment.