Remove Passport and replace with Sanctum, upgrade framework to Laravel 10

This commit is contained in:
Deon George 2023-06-26 12:32:38 +12:00
parent 75549590fc
commit b70a36003a
22 changed files with 1294 additions and 2865 deletions

View File

@ -35,13 +35,13 @@ class Kernel extends HttpKernel
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
\App\Http\Middleware\AddUserToView::class,
],
'api' => [
'throttle:60,1',
'bindings',
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

View File

@ -16,7 +16,9 @@ class Echoarea extends Model
private const CACHE_TIME = 3600;
protected $dates = [ 'last_message' ];
protected $casts = [
'last_message' => 'datetime:Y-m-d H:i:s'
];
/* RELATIONS */

View File

@ -26,11 +26,12 @@ final class Echomail extends Model implements Packet
private bool $no_export = FALSE;
protected $casts = [
'datetime' => 'datetime:Y-m-d H:i:s',
'kludges' => CollectionOrNull::class,
'rogue_seenby' => CollectionOrNull::class,
'rogue_path' => CollectionOrNull::class,
'msg' => CompressedString::class,
'msg_src' => CompressedString::class,
'rogue_seenby' => CollectionOrNull::class,
'rogue_path' => CollectionOrNull::class,
];
private const cast_utf8 = [
@ -44,8 +45,6 @@ final class Echomail extends Model implements Packet
'tagline',
];
protected $dates = ['datetime'];
public function __set($key,$value)
{
switch ($key) {

View File

@ -22,10 +22,11 @@ class File extends Model
protected $casts = [
'kludges' => CollectionOrNull::class,
'rogue_seenby' => CollectionOrNull::class,
'rogue_path' => CollectionOrNull::class,
'datetime' => 'datetime:Y-m-d H:i:s',
'desc' => CompressedString::class,
'ldesc' => CompressedString::class,
'rogue_seenby' => CollectionOrNull::class,
'rogue_path' => CollectionOrNull::class,
'size' => 'int',
];
@ -34,8 +35,6 @@ class File extends Model
'ldesc',
];
protected $dates = ['datetime'];
public function __set($key,$value)
{
switch ($key) {

View File

@ -33,11 +33,11 @@ final class Netmail extends Model implements Packet
'tagline',
];
protected $dates = ['datetime','sent_at'];
protected $casts = [
'datetime' => 'datetime:Y-m-d H:i:s',
'msg' => CompressedString::class,
'msg_src' => CompressedString::class,
'sent_at' => 'datetime:Y-m-d H:i:s',
];
public function __set($key,$value)

View File

@ -9,7 +9,10 @@ class Nodelist extends Model
{
use SoftDeletes;
protected $dates = ['date'];
protected $casts = [
'date' => 'datetime:Y-m-d H:i:s'
];
protected $fillable = ['date','domain_id'];
public const definitions = ['Zone','Region','Host','Hub','Pvt','Hold','Down'];

View File

@ -11,7 +11,9 @@ class System extends Model
{
use HasFactory;
protected $dates = ['last_session'];
protected $casts = [
'last_session' => 'datetime:Y-m-d H:i:s'
];
/* SCOPES */

View File

@ -6,7 +6,7 @@ use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Laravel\Sanctum\HasApiTokens;
use App\Traits\UserSwitch;
@ -56,10 +56,9 @@ class User extends Authenticatable implements MustVerifyEmail
*/
protected $casts = [
'email_verified_at' => 'datetime',
'last_on' => 'datetime:Y-m-d H:i:s'
];
protected $dates = ['last_on'];
/* RELATIONS */
public function systems()

View File

@ -5,7 +5,6 @@ namespace App\Providers;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\ServiceProvider;
use Laravel\Passport\Passport;
use App\Notifications\Channels\NetmailChannel;
use App\Models\Netmail;
@ -22,8 +21,6 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
Passport::ignoreMigrations();
Notification::resolved(function (ChannelManager $service) {
$service->extend('netmail', function ($app) {
return new NetmailChannel($app->make(Netmail::class));

View File

@ -2,34 +2,32 @@
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [ "framework", "laravel" ],
"keywords": ["framework","laravel"],
"license": "MIT",
"require": {
"php": "^8.0",
"php": "^8.1|8.2",
"ext-pcntl": "*",
"ext-sockets": "*",
"ext-zip": "*",
"ext-zlib": "*",
"ext-zstd": "*",
"doctrine/dbal": "^3.5",
"eduardokum/laravel-mail-auto-embed": "^2.0",
"fruitcake/laravel-cors": "^2.0",
"laravel/framework": "^9.0",
"laravel/passport": "^10.1",
"laravel/ui": "^3.2",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/ui": "^4.0",
"league/flysystem-aws-s3-v3": "^3.0",
"nunomaduro/laravel-console-summary": "^1.8",
"nunomaduro/laravel-console-summary": "^1.9",
"rennokki/laravel-eloquent-query-cache": "^3.3",
"repat/laravel-job-models": "^0.7",
"repat/laravel-job-models": "^0.8",
"romanzipp/laravel-queue-monitor": "^2.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.6",
"fakerphp/faker": "^1.9.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.3.3",
"spatie/laravel-ignition": "^1.0"
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.1"
},
"autoload": {
"files": [
@ -74,6 +72,6 @@
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true
}

3961
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,7 @@ return [
],
'api' => [
'driver' => 'passport',
'driver' => 'sanctum',
'provider' => 'users',
'hash' => false,
],

View File

@ -31,7 +31,6 @@ return [
'notifications:table',
'optimize:*',
'package:discover',
'passport:*',
'queue:*',
'route:*',
'serve',

View File

@ -1,33 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<coverage/>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="MAIL_DRIVER" value="array"/>
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit>

View File

@ -434,7 +434,7 @@
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('api/default') }}/'+item.attributes.itemid.nodeValue,
url: '{{ url('default') }}/'+item.attributes.itemid.nodeValue,
cache: false
})
});

View File

@ -213,7 +213,7 @@
if (! $('#node-address').hasClass('d-none'))
$('#node-address').addClass('d-none');
$.get('{{ url('api/regions') }}'+'/'+this.value,function(data) {
$.get('{{ url('regions') }}'+'/'+this.value,function(data) {
$('#region_id').append('<option value=""></option>');
$('#region_id').append('<option value="0">No Region</option>');
$('#region_id').append('<option value="new">New Region</option>');
@ -300,7 +300,7 @@
$('#host_id').children().remove();
var that = this;
$.get('{{ url('api/hosts') }}'+'/'+$('#zone_id').val()+'/'+this.value,function(data) {
$.get('{{ url('hosts') }}'+'/'+$('#zone_id').val()+'/'+this.value,function(data) {
$('#host_id').append('<option value=""></option>');
if (that.value !== '0')
$('#host_id').append('<option value="0">No Host</option>');
@ -369,7 +369,7 @@
$('#hub_id').prop('disabled',true);
$('#hub_id').children().remove();
$.get('{{ url('api/hubs') }}'+'/'+$('#zone_id').val()+'/'+this.value,function(data) {
$.get('{{ url('hubs') }}'+'/'+$('#zone_id').val()+'/'+this.value,function(data) {
$('#hub_id').append('<option value="">No Hub</option>');
data.forEach(function(item) {

View File

@ -125,7 +125,7 @@
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('api/system/address',[$o->id]) }}',
url: '{{ url('system/address',[$o->id]) }}',
cache: false
})
});

View File

@ -112,7 +112,7 @@
if (e.status != 412)
alert('That didnt work? Please try again....');
},
url: '{{ url('api/system/address',[$o->id]) }}',
url: '{{ url('system/address',[$o->id]) }}',
cache: false
})
});

View File

@ -149,7 +149,7 @@
selectOnBlur: false,
appendTo: "#address_search_results",
source: function (query,process) {
addresssearch('{{ url('api/addresses/orphan') }}',query,process);
addresssearch('{{ url('addresses/orphan') }}',query,process);
},
matcher: function () { return true; },

View File

@ -182,7 +182,7 @@
selectOnBlur: false,
appendTo: "#system_search_results",
source: function (query,process) {
systemsearch('{{ url('api/systems/orphan') }}',query,process);
systemsearch('{{ url('systems/orphan') }}',query,process);
},
matcher: function () { return true; },

View File

@ -14,18 +14,3 @@ use App\Http\Controllers\{DomainController,SystemController,ZoneController};
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware(['auth:api'])->group(function () {
Route::get('regions/{o}',[DomainController::class,'api_regions'])
->where('o','[0-9]+');
Route::get('hosts/{o}/{region}',[DomainController::class,'api_hosts'])
->where('o','[0-9]+');
Route::get('systems/orphan',[SystemController::class,'api_orphan']);
Route::get('addresses/orphan',[SystemController::class,'api_orphan_address']);
Route::get('hubs/{o}/{host}',[DomainController::class,'api_hubs'])
->where('o','[0-9]+');
Route::post('default/{o}',[ZoneController::class,'api_default'])
->where('o','[0-9]+');
Route::post('system/address/{o}',[SystemController::class,'api_address'])
->where('o','[0-9]+');
});

View File

@ -38,35 +38,39 @@ Route::get('logout',[LoginController::class,'logout']);
Route::get('admin/switch/start/{o}',[UserSwitchController::class,'user_switch_start']);
Route::get('admin/switch/stop',[UserSwitchController::class,'user_switch_stop']);
// Unauthed routes
Route::get('/',[HomeController::class,'home']);
Route::view('about','about');
Route::view('domain/list','domain.list');
Route::get('network/{o}',[HomeController::class,'network'])
->where('o','[0-9]+');
Route::match(['get','post'],'pkt',[HomeController::class,'pkt']);
Route::view('system/list','system.list');
Route::get('system/view/{o}',[SystemController::class,'view'])
->where('o','[0-9]+');
Route::get('search',[HomeController::class,'search']);
Route::middleware(['auth','verified','activeuser'])->group(function () {
Route::get('addresses/orphan',[SystemController::class,'api_orphan_address']);
Route::get('dashboard',[UserController::class,'dashboard']);
Route::match(['get','post'],'link',[UserController::class,'link']);
Route::post('default/{o}',[ZoneController::class,'api_default'])
->where('o','[0-9]+');
Route::get('ftn/domain',[DomainController::class,'home']);
Route::match(['get','post'],'ftn/domain/addedit/{o?}',[DomainController::class,'add_edit'])
->where('o','[0-9]+');
Route::get('ftn/echoarea',[EchoareaController::class,'home']);
Route::match(['get','post'],'ftn/echoarea/addedit/{o?}',[EchoareaController::class,'add_edit'])
->where('o','[0-9]+');
Route::get('ftn/filearea',[FileareaController::class,'home']);
Route::match(['get','post'],'ftn/filearea/addedit/{o?}',[FileareaController::class,'add_edit'])
->where('o','[0-9]+');
Route::get('ftn/our_systems',[SystemController::class,'ours']);
Route::get('ftn/system',[SystemController::class,'home']);
Route::match(['get','post'],'ftn/system/addedit/{o?}',[SystemController::class,'add_edit'])
->where('o','[0-9]+');
Route::get('ftn/our_systems',[SystemController::class,'ours']);
Route::post('ftn/system/addaddress/{o}',[SystemController::class,'add_address'])
->where('o','[0-9]+');
Route::post('ftn/system/addsession/{o}',[SystemController::class,'add_session'])
@ -89,26 +93,30 @@ Route::middleware(['auth','verified','activeuser'])->group(function () {
->where('o','[0-9]+');
Route::get('ftn/system/susaddress/{o}',[SystemController::class,'sus_address'])
->where('o','[0-9]+');
Route::get('ftn/zone',[ZoneController::class,'home']);
Route::match(['get','post'],'ftn/zone/addedit/{o?}',[ZoneController::class,'add_edit'])
->where('o','[0-9]+');
Route::get('hosts/{o}/{region}',[DomainController::class,'api_hosts'])
->where('o','[0-9]+');
Route::get('hubs/{o}/{host}',[DomainController::class,'api_hubs'])
->where('o','[0-9]+');
Route::match(['get','post'],'link',[UserController::class,'link']);
Route::get('permissions',[HomeController::class,'permissions']);
Route::get('regions/{o}',[DomainController::class,'api_regions'])
->where('o','[0-9]+');
Route::post('system/address/{o}',[SystemController::class,'api_address'])
->where('o','[0-9]+');
Route::get('systems/orphan',[SystemController::class,'api_orphan']);
Route::match(['get','post'],'user/system/register',[SystemController::class,'system_register']);
Route::match(['post'],'user/system/link',[SystemController::class,'system_link']);
});
Route::get('network/{o}',[HomeController::class,'network']);
Route::get('permissions',[HomeController::class,'permissions']);
Route::match(['get','post'],'pkt',[HomeController::class,'pkt']);
Route::get('search',[HomeController::class,'search']);
Route::middleware(['auth','can:admin'])->group(function () {
Route::match(['get','post'],'setup',[HomeController::class,'setup']);
Route::get('echomail/view/{o}',[EchomailController::class,'view']);
Route::get('netmail/view/{o}',[NetmailController::class,'view']);
Route::get('user/list',[UserController::class,'home']);
Route::match(['get','post'],'setup',[HomeController::class,'setup']);
Route::match(['get','post'],'user/addedit/{o?}',[UserController::class,'add_edit'])
->where('o','[0-9]+');
});