Users
Class BlackFox\Users is the heir of SCRUD, describes the user table.
Fields
Code | Type | Name | Description | |
---|---|---|---|---|
ID | * | NUMBER | ID | |
LOGIN | * | STRING | Login | |
PASSWORD | * | PASSWORD | Password | Database contains sha1 hash of the password |
SALT | * | STRING | Salt | |
HASH | STRING | Hash | For password recovery | |
LANGUAGE | STRING | Language | ||
LAST_AUTH | DATETIME | Last authorization moment | ||
REGISTER_MOMENT | DATETIME | Registration moment | ||
FIRST_NAME | STRING | First name | ||
LAST_NAME | STRING | Last name | ||
MIDDLE_NAME | STRING | Middle name | ||
STRING | ||||
PHONE | STRING | Phone | ||
AVATAR | FILE | Avatar | 120x120 | |
BIRTH_DAY | DATE | Birthday | ||
ABOUT | TEXT | About | ||
GROUPS | INNER | Groups |
$Users = \BlackFox\Users::I(); $user = $Users->Read(['LOGIN' => 'Root']); if (empty($user)) throw new \BlackFox\ExceptionElementNotFound(); $Users->Update($user['ID'], [ 'FIRST_NAME' => 'Root', 'EMAIL' => 'email@email.com', ]); $Users->AddGroup($user['ID'], 'root'); $Users->SetPassword($user['ID'], '123456'); if (!$Users->CheckPassword($user['ID'], '123456')) throw new \BlackFox\ExceptionAccessDenied(); $recovery_string = $Users->GetRecoveryString($user['ID']);
Methods
Along with all the methods that SCRUD provides, the class has additional methods:
Name | Parameters | Description |
---|---|---|
SetPassword | $ID, $password | Sets a new password |
CheckPassword | $ID, $password | Verify password |
AddGroup | $ID, $group | Adds the user to the group |
GetRecoveryString | $ID | Generates and returns a new line for password recovery (HASH) |
Class override
If you are not satisfied with the set of fields and methods described above, you should
create a derived class from
namespace Example; class Users extends \BlackFox\Users { public function Init() { unset($this->fields['AVATAR']); $this->fields += [ 'VK_ID' => [ 'TYPE' => 'NUMBER', 'NAME' => 'Vk identifier', ], ]; } }
/config.php
<?php return [ // ... 'overrides' => [ // ... 'BlackFox\Users' => 'Example\Users', ], ];