Added laravel/passport, assign ftn addresses to nodes

This commit is contained in:
Deon George
2021-06-20 23:03:20 +10:00
parent 84df9ce811
commit 7cab4e288b
24 changed files with 1163 additions and 176 deletions

52
app/Models/Address.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Http\Controllers\DomainController;
class Address extends Model
{
/* RELATIONS */
public function system()
{
return $this->belongsTo(System::class);
}
public function zone()
{
return $this->belongsTo(Zone::class);
}
/* ATTRIBUTES */
/**
* Render the node name in full 5D
*
* @return string
*/
public function getFTNAttribute()
{
return sprintf('%d:%d/%d.%d@%s',$this->zone->zone_id,$this->host_id ?: $this->region_id,$this->node_id,$this->point_id,$this->zone->domain->name);
}
public function getRoleAttribute($value)
{
switch ($value) {
case DomainController::NODE_ZC;
return 'Zone';
case DomainController::NODE_RC;
return 'Region';
case DomainController::NODE_NC;
return 'Host';
case DomainController::NODE_HC;
return 'Hub';
case NULL:
return 'Node';
default:
return '?';
}
}
}

View File

@@ -15,5 +15,14 @@ class System extends Model
/* RELATIONS */
public function addresses()
{
return $this->hasMany(Address::class)
->orderBy('region_id')
->orderBy('host_id')
->orderBy('node_id')
->orderBy('point_id');
}
/* CASTS */
}

View File

@@ -6,40 +6,68 @@ 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;
/**
* Class User
*
* User Roles:
* + Site Admin
* + ZC - For Domain/Zone
* + RC - For sub portion of a Domain/Zone (aka Region)
* + Host Admin - For sub portion of a Region
* + Hub Admin - For a sub portion of a Hosts system
* + Sysop - Individual system
* + Guest
*
* @package App\Models
*/
class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable;
use HasFactory,Notifiable,HasApiTokens;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
protected $dates = ['last_on'];
protected $dates = ['last_on'];
/* GENERAL METHODS */
/**
* See if the user is already a member of the chosen network
*
* @param Domain $o
* @return bool
*/
public function isMember(Domain $o): bool
{
return FALSE;
}
}

View File

@@ -12,6 +12,11 @@ class Zone extends Model
/* RELATIONS */
public function addresses()
{
return $this->hasMany(Address::class);
}
public function domain()
{
return $this->belongsTo(Domain::class);