2018-11-15 10:45:49 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-03 12:53:40 +00:00
|
|
|
namespace App\Models;
|
2018-11-15 10:45:49 +00:00
|
|
|
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
2021-05-03 12:53:40 +00:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2018-11-15 10:45:49 +00:00
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2021-05-03 12:53:40 +00:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
2023-12-18 02:00:04 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2023-06-26 00:32:38 +00:00
|
|
|
use Laravel\Sanctum\HasApiTokens;
|
2018-11-15 10:45:49 +00:00
|
|
|
|
2023-08-02 12:42:59 +00:00
|
|
|
use App\Traits\{ScopeActive,UserSwitch};
|
2021-09-27 12:50:47 +00:00
|
|
|
|
2021-06-20 13:03:20 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2021-06-13 13:00:26 +00:00
|
|
|
class User extends Authenticatable implements MustVerifyEmail
|
2018-11-15 10:45:49 +00:00
|
|
|
{
|
2023-08-02 12:42:59 +00:00
|
|
|
use HasFactory,Notifiable,HasApiTokens,UserSwitch,ScopeActive;
|
2021-06-20 13:03:20 +00:00
|
|
|
|
2023-08-10 02:17:01 +00:00
|
|
|
/** @var int Enables users have unlimited online time in the BBS */
|
|
|
|
public const FLAG_H = 1<<12;
|
|
|
|
|
2021-06-20 13:03:20 +00:00
|
|
|
/**
|
|
|
|
* 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 cast to native types.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'email_verified_at' => 'datetime',
|
2024-04-25 05:27:45 +00:00
|
|
|
'last_on' => 'datetime:Y-m-d H:i:s',
|
|
|
|
'passkey' => 'json',
|
2021-06-20 13:03:20 +00:00
|
|
|
];
|
|
|
|
|
2021-10-26 12:19:55 +00:00
|
|
|
/* RELATIONS */
|
|
|
|
|
2023-08-02 12:42:59 +00:00
|
|
|
public function system()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(System::class);
|
|
|
|
}
|
|
|
|
|
2021-10-26 12:19:55 +00:00
|
|
|
public function systems()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(System::class);
|
|
|
|
}
|
|
|
|
|
2021-06-20 13:03:20 +00:00
|
|
|
/* GENERAL METHODS */
|
|
|
|
|
2024-04-26 06:18:40 +00:00
|
|
|
public function addresses(Domain $o=NULL): Collection
|
2023-12-19 00:45:11 +00:00
|
|
|
{
|
|
|
|
return Address::select('addresses.*')
|
|
|
|
->join('systems',['systems.id'=>'addresses.system_id'])
|
|
|
|
->join('system_user',['system_user.system_id'=>'systems.id'])
|
2024-04-26 06:18:40 +00:00
|
|
|
->when(! is_null($o),function($query) use ($o) {
|
|
|
|
return $query
|
|
|
|
->join('zones',['zones.id'=>'addresses.zone_id'])
|
|
|
|
->where('zones.domain_id',$o->id);
|
|
|
|
})
|
2023-12-19 00:45:11 +00:00
|
|
|
->where('system_user.user_id',$this->id)
|
2024-05-24 01:04:25 +00:00
|
|
|
->activeFTN()
|
2023-12-19 00:45:11 +00:00
|
|
|
->with(['zone.domain'])
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2023-08-10 02:17:01 +00:00
|
|
|
public function hasExemption(int $flag): bool
|
|
|
|
{
|
|
|
|
// @todo To implement
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2022-12-11 10:46:08 +00:00
|
|
|
/**
|
|
|
|
* Is this user a ZC of a domain?
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isZC(): bool
|
|
|
|
{
|
2023-12-18 02:00:04 +00:00
|
|
|
return $this->zc()->count() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
2024-05-09 11:22:30 +00:00
|
|
|
* @deprecated not used - but if it is, probably could use Address::points()?
|
2023-12-18 02:00:04 +00:00
|
|
|
*/
|
|
|
|
public function points(): Collection
|
|
|
|
{
|
|
|
|
$result = collect();
|
|
|
|
|
|
|
|
foreach($this->systems->pluck('addresses')->flatten()->where('role','>',Address::NODE_HC) as $ao)
|
|
|
|
$result = $result->merge($ao->children());
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the zones that this user is ZC for
|
|
|
|
*
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function zc(): Collection
|
|
|
|
{
|
2024-05-09 11:22:30 +00:00
|
|
|
$this->load('systems.addresses.nodes_hub');
|
2024-04-26 06:18:40 +00:00
|
|
|
|
2024-05-09 11:22:30 +00:00
|
|
|
return $this->systems->pluck('addresses')->flatten()->where('role_id',Address::NODE_ZC);
|
2022-12-11 10:46:08 +00:00
|
|
|
}
|
2018-11-15 10:45:49 +00:00
|
|
|
}
|