Work on registration of existing systems to users
This commit is contained in:
@@ -7,6 +7,7 @@ use Exception;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -369,6 +370,41 @@ class Address extends Model
|
||||
return ($o && $o->system->active) ? $o : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an activation code for this address
|
||||
*
|
||||
* @param User $uo
|
||||
* @return string
|
||||
*/
|
||||
public function set_activation(User $uo): string
|
||||
{
|
||||
return sprintf('%x:%s',
|
||||
$this->id,
|
||||
substr(md5(sprintf('%d:%x',$uo->id,timew($this->updated_at))),0,10)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the user's activation code for this address is correct
|
||||
*
|
||||
* @param User $uo
|
||||
* @param string $code
|
||||
* @return bool
|
||||
*/
|
||||
public function check_activation(User $uo,string $code): bool
|
||||
{
|
||||
try {
|
||||
Log::info(sprintf('%s:Checking Activation code [%s] invalid for user [%d]',self::LOGKEY,$code,$uo->id));
|
||||
|
||||
return ($code == $this->set_activation($uo));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error(sprintf('%s:! Activation code [%s] invalid for user [%d]',self::LOGKEY,$code,$uo->id));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Netmail waiting to be sent to this system
|
||||
*
|
||||
|
@@ -9,13 +9,13 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Interfaces\Packet;
|
||||
use App\Traits\EncodeUTF8;
|
||||
use App\Traits\{EncodeUTF8,MsgID};
|
||||
|
||||
final class Netmail extends Model implements Packet
|
||||
{
|
||||
private const LOGKEY = 'MN-';
|
||||
|
||||
use SoftDeletes,EncodeUTF8;
|
||||
use SoftDeletes,EncodeUTF8,MsgID;
|
||||
|
||||
private const cast_utf8 = [
|
||||
'to',
|
||||
|
@@ -8,7 +8,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
/**
|
||||
* Class Setup
|
||||
* This class represents our configuration.
|
||||
*
|
||||
* Our 'System' is defined by system_id, and from it we can find out our BBS name and addresses.
|
||||
*
|
||||
* @package App\Models
|
||||
* @property Collection nodes
|
||||
@@ -47,37 +49,6 @@ class Setup extends Model
|
||||
// Our non model attributes and values
|
||||
private array $internal = [];
|
||||
|
||||
public static function product_id(int $c=self::PRODUCT_ID): string
|
||||
{
|
||||
return hexstr($c);
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function system()
|
||||
{
|
||||
return $this->belongsTo(System::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getLocationAttribute()
|
||||
{
|
||||
return $this->system->location;
|
||||
}
|
||||
|
||||
public function getSysopAttribute()
|
||||
{
|
||||
return $this->system->sysop;
|
||||
}
|
||||
|
||||
public function getSystemNameAttribute()
|
||||
{
|
||||
return $this->system->name;
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
@@ -143,6 +114,49 @@ class Setup extends Model
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Mailer Product ID in hex.
|
||||
*
|
||||
* @param int $c
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function product_id(int $c=self::PRODUCT_ID): string
|
||||
{
|
||||
return hexstr($c);
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
/**
|
||||
* The defined system that this setup is valid for
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function system()
|
||||
{
|
||||
return $this->belongsTo(System::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getLocationAttribute()
|
||||
{
|
||||
return $this->system->location;
|
||||
}
|
||||
|
||||
public function getSysopAttribute()
|
||||
{
|
||||
return $this->system->sysop;
|
||||
}
|
||||
|
||||
public function getSystemNameAttribute()
|
||||
{
|
||||
return $this->system->name;
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/* BINKP OPTIONS: BINKP_OPT_* */
|
||||
|
||||
public function binkpOptionClear(int $key): void
|
||||
|
@@ -133,4 +133,20 @@ class System extends Model
|
||||
return $item->role & $type;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the addresses and return which ones are in my zones
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Collection $addresses
|
||||
* @param int $type
|
||||
* @return Collection
|
||||
*/
|
||||
public function inMyZones(Collection $addresses,int $type=(Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection
|
||||
{
|
||||
$myzones = $this->addresses->pluck('zone_id')->unique();
|
||||
|
||||
return $addresses->filter(function($item) use ($myzones,$type) {
|
||||
return ($item->role & $type) && ($myzones->search($item->zone_id) !== FALSE);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user