Tuskfish API V1.1.2
  • Package
  • Class

Packages

  • content
  • core
  • database
  • installation
  • security
  • user
  • utilities

Classes

  • TfArticle
  • TfAudio
  • TfBlock
  • TfBlockHandler
  • TfCache
  • TfCollection
  • TfCollectionHandler
  • TfContentControllerFactory
  • TfContentHandler
  • TfContentHandlerFactory
  • TfContentObject
  • TfContentObjectController
  • TfCriteria
  • TfCriteriaFactory
  • TfCriteriaItem
  • TfDatabase
  • TfDownload
  • TfFileHandler
  • TfImage
  • TfLogger
  • TfMetadata
  • TfPaginationControl
  • TfPreference
  • TfPreferenceHandler
  • TfRss
  • TfSearchContent
  • TfSession
  • TfStatic
  • TfTag
  • TfTagHandler
  • TfTaglinkHandler
  • TfTemplate
  • TfTree
  • TfUser
  • TfUtils
  • TfValidator
  • TfValidatorFactory
  • TfVideo
  • TfYubikeyAuthenticator

Traits

  • TfContentTypes
  • TfLanguage
  • TfMagicMethods
  • TfMimetypes
  • TfRights

Functions

  • checkPasswordStrength
  • getUrl
  • hashPassword
  • tf_autoload
  • tfContentModuleAutoload
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 
<?php

/**
 * TfUser class file.
 * 
 * @copyright   Simon Wilkinson 2013+ (https://tuskfish.biz)
 * @license     https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License (GPL) V2
 * @author      Simon Wilkinson <[email protected]>
 * @version     Release: 1.0
 * @since       1.0
 * @package     user
 */

// Enable strict type declaration.
declare(strict_types=1);

if (!defined("TFISH_ROOT_PATH")) die("TFISH_ERROR_ROOT_PATH_NOT_DEFINED");

/** 
 * Represents a user.
 *
 * @copyright   Simon Wilkinson 2013+ (https://tuskfish.biz)
 * @license     https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License (GPL) V2
 * @author      Simon Wilkinson <[email protected]>
 * @version     Release: 1.0
 * @since       1.0
 * @package     user
 * @uses        trait TfMagicMethods Prevents direct setting of properties / unlisted properties.
 * @property    TfValidator $validator Instance of the Tuskfish data validator class.
 * @property    int $id ID of this user
 * @property    string $adminEmail email address of this user
 * @property    string $passwordHash
 * @property    int $userGroup The privilege group this user belongs to (not implemented).
 * @property    string $yubikeyId ID of the primary Yubikey hardware authentication token
 * for this account.
 * @property    string $yubikeyId2 ID of the secondary Yubikey hardware authentication token for
 * this account.
 * @property    string $loginErrors Number of times the user has failed to enter their password
 * correctly. It is reset to zero on successful login.
 */
class TfUser
{
    
    use TfMagicMethods;

    protected $validator;
    protected $id;
    protected $adminEmail;
    protected $passwordHash;
    protected $userGroup;
    protected $yubikeyId;
    protected $yubikeyId2;
    protected $loginErrors;
    
    /**
     * Constructor.
     * 
     * @param TfValidator $validator An instance of the Tuskfish data validator class.
     */
    public function __construct(TfValidator $validator)
    {
        if (is_a($validator, 'TfValidator')) {
            $this->validator = $validator; 
        } else {
            trigger_error(TFISH_ERROR_NOT_VALIDATOR, E_USER_ERROR);
        }
    }
    
    /**
     * Get the value of a property.
     * 
     * Intercepts direct calls to access an object property. Disallow public access to sensitive
     * properties (passwordHash).
     * 
     * @param string $property Name of property.
     * @return mixed|null $property Value of property if it is set; otherwise null.
     */
    public function __get(string $property)
    {
        $cleanProperty = $this->validator->trimString($property);
        
        if (isset($cleanProperty) && $cleanProperty !== 'passwordHash') {
            return $this->$cleanProperty;
        } else {
            return null;
        }
    }
    
    /**
     * Set the administrator's email address.
     * 
     * @param string $email Email of the administrator of this website.
     */
    public function setAdminEmail(string $email)
    {
        $cleanEmail = $this->validator->trimString($email);

        if ($this->validator->isEmail($cleanEmail)) {
            $this->adminEmail = $cleanEmail;
        } else {
            trigger_error(TFISH_ERROR_NOT_EMAIL, E_USER_ERROR);
        }
    }
    
    /**
     * Set the ID for this account.
     * 
     * @param int $id ID of this user account.
     */
    public function setId(int $id)
    {
        $cleanId = (int) $id;
        
        if ($this->validator->isInt($cleanId, 1)) {    
            $this->id = $cleanId;
        } else {
            trigger_error(TFISH_ERROR_NOT_INT, E_USER_ERROR);
        }
    }
    
    /**
     * Set the number of times this user has failed to correctly enter their password.
     * 
     * Set this value to zero on successful login.
     * 
     * @param int $number_of_errors Number of failed login attempts.
     */
    public function setLoginErrors(int $number_of_errors)
    {
        $clean_number_of_errors = (int) $number_of_errors;
        
        if ($this->validator->isInt($clean_number_of_errors, 0)) {
            $this->loginErrors = $clean_number_of_errors;
        }  else {
            trigger_error(TFISH_ERROR_NOT_INT, E_USER_ERROR);
        }
    }    
    
    /**
     * Set the password hash for this user.
     * 
     * @param string $hash Hash of the user's password.
     */
    public function setPasswordHash(string $hash)
    {
        $clean_hash = $this->validator->trimString($hash);
        $this->passwordHash = $clean_hash;
    }
    
    /**
     * Set the privilege group for this user (not implemented).
     * 
     * @param int $group User group.
     */
    public function setUserGroup(int $group)
    {
        $clean_group = (int) $group;
        
        if ($this->validator->isInt($clean_group, 1)) {
            $this->userGroup = $clean_group;
        } else {
            trigger_error(TFISH_ERROR_NOT_INT, E_USER_ERROR);
        }
    }
    
    /**
     * Set the ID of the primary yubikey hardware token for this account.
     * 
     * @param string $id Yubikey ID.
     */
    public function setYubikeyId(string $id)
    {
        $cleanId = $this->validator->trimString($id);
        $this->yubikeyId = $cleanId;
    }
    
    /**
     * Set the ID of the secondary yubikey hardware token for this account.
     * 
     * @param string $id Yubikey ID.
     */
    public function setYubikeyId2(string $id)
    {
        $cleanId = $this->validator->trimString($id);
        $this->yubikeyId2 = $cleanId;
    }

}
Tuskfish API V1.1.2 API documentation generated by ApiGen