Users

Class System\Users is the heir to 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
EMAIL STRING Email
PHONE STRING Phone
AVATAR FILE Avatar 120x120
BIRTH_DAY DATE Birthday
ABOUT TEXT About
GROUPS INNER Groups
$Users = \System\Users::I();

$user = $Users->Read(['LOGIN' => 'Root']);
if (empty($user))
	throw new \System\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 \System\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 System\Users, add\modify\remove fields\methods, and override the class in configurations.

namespace Example;
class Users extends \System\Users {
	public function Init() {
		unset($this->structure['AVATAR']);
		$this->structure += [
			'VK_ID' => [
				'TYPE' => 'NUMBER',
				'NAME' => 'Vk identifier',
			],
		];
	}
}
/config.php
<?php
global $CONFIG;
$CONFIG = [
	// ...
	'redirects' => [
		// ...
		'System\Users' => 'Example\Users',
	],
];
return $CONFIG;
Ask question