146 lines
4.1 KiB
PHP
Executable File
146 lines
4.1 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* FuzeWorks Authentication Plugin.
|
|
*
|
|
* The FuzeWorks PHP FrameWork
|
|
*
|
|
* Copyright (C) 2013 - 2023 i15
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
* @author i15
|
|
* @copyright Copyright (C) 2013 - 2023, i15. (https://i15.nl)
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
|
*
|
|
* @since Version 1.3.0
|
|
*
|
|
* @version Version 1.3.0
|
|
*/
|
|
|
|
namespace FuzeWorks\Authentication\Model;
|
|
|
|
class User
|
|
{
|
|
|
|
/**
|
|
* A 16 character random id of the user.
|
|
*
|
|
* @var string
|
|
*/
|
|
public string $id;
|
|
|
|
/**
|
|
* The primary identifier for the user.
|
|
*
|
|
* Emails will get sent to this address.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
public ?string $primaryEmail;
|
|
|
|
/**
|
|
* The password of the user, as created by the password_hash() function.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
public ?string $password;
|
|
|
|
/**
|
|
* A secret key used to generate TOTP tokens.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
public ?string $mfaSecret = null;
|
|
|
|
/**
|
|
* Separated permission nodes this user has access to.
|
|
*
|
|
* @var array
|
|
*/
|
|
public array $permissions = [];
|
|
|
|
/**
|
|
* Whether this user is active or not.
|
|
*
|
|
* If false, user should be blocked from logging in or continuing a session.
|
|
*
|
|
* @var bool
|
|
*/
|
|
public bool $active;
|
|
|
|
/**
|
|
* A 16 character random token used to verify the email belongs to the user.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
public ?string $emailVerifyToken;
|
|
|
|
/**
|
|
* A unix int timestamp before which time the user needs to have verified their email.
|
|
*
|
|
* @var int|null
|
|
*/
|
|
public ?int $emailVerifyExpiry;
|
|
|
|
/**
|
|
* A key => value list of other properties describing the user, such as username or social info.
|
|
*
|
|
* @var array
|
|
*/
|
|
public array $properties = [];
|
|
|
|
public function __construct(string $id, string $primaryEmail = null, string $password = null, array $permissions = [], bool $active = true, string $emailToken = null, int $emailExpire = null, array $properties = [])
|
|
{
|
|
$this->id = $id;
|
|
$this->primaryEmail = $primaryEmail;
|
|
$this->password = $password;
|
|
$this->permissions = $permissions;
|
|
$this->active = $active;
|
|
$this->emailVerifyToken = $emailToken;
|
|
$this->emailVerifyExpiry = $emailExpire;
|
|
$this->properties = $properties;
|
|
}
|
|
|
|
/**
|
|
* Returns true if the user has access to a specific permission node.
|
|
*
|
|
* @param string $permissionTag
|
|
* @return bool
|
|
*/
|
|
public function hasPermission(string $permissionTag): bool
|
|
{
|
|
return in_array(strtoupper($permissionTag), $this->permissions) || in_array("SUPER", $this->permissions);
|
|
}
|
|
|
|
public function __isset(string $name)
|
|
{
|
|
return isset($this->properties[$name]);
|
|
}
|
|
|
|
public function __get(string $name)
|
|
{
|
|
return $this->properties[$name];
|
|
}
|
|
|
|
public function __set(string $name, mixed $value)
|
|
{
|
|
$this->properties[$name] = $value;
|
|
}
|
|
|
|
} |