Skip to content

Commit

Permalink
kw_auth - user id and group id as string, can set only some of values
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kalanis committed May 14, 2023
1 parent f03d234 commit eaba003
Show file tree
Hide file tree
Showing 36 changed files with 341 additions and 290 deletions.
38 changes: 15 additions & 23 deletions php-src/Data/FileGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,30 @@
*/
class FileGroup implements IGroup
{
/** @var int */
protected $id = 0;
/** @var string */
protected $id = '0';
/** @var string */
protected $name = '';
/** @var int */
protected $author = 0;
/** @var string */
protected $author = '0';
/** @var string */
protected $displayName = '';
/** @var int */
protected $status = 0;
/** @var int[] */
/** @var string[] */
protected $parents = [];

/**
* @param int $id
* @param string $name
* @param int $author
* @param string $display
* @param int $status
* @param int[] $parents
*/
public function setData(int $id, string $name, int $author, string $display, int $status, array $parents = []): void
public function setGroupData(?string $id, ?string $name, ?string $desc, ?string $authorId, ?int $status, ?array $parents = []): void
{
$this->id = $id;
$this->name = $name;
$this->author = $author;
$this->displayName = $display;
$this->status = $status;
$this->parents = $parents;
$this->id = $id ?? $this->id;
$this->name = $name ?? $this->name;
$this->displayName = $desc ?? $this->displayName;
$this->author = $authorId ?? $this->author;
$this->status = $status ?? $this->status;
$this->parents = $parents ?? $this->parents;
}

public function getGroupId(): int
public function getGroupId(): string
{
return $this->id;
}
Expand All @@ -53,7 +45,7 @@ public function getGroupName(): string
return $this->name;
}

public function getGroupAuthorId(): int
public function getGroupAuthorId(): string
{
return $this->author;
}
Expand All @@ -69,7 +61,7 @@ public function getGroupStatus(): int
}

/**
* @return int[]
* @return string[]
*/
public function getGroupParents(): array
{
Expand Down
26 changes: 13 additions & 13 deletions php-src/Data/FileUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
*/
class FileUser implements IUser
{
/** @var int */
protected $authId = 0;
/** @var string */
protected $authId = '0';
/** @var string */
protected $authName = '';
/** @var int */
protected $authGroup = 0;
/** @var string */
protected $authGroup = '0';
/** @var int */
protected $authClass = 0;
/** @var int|null */
Expand All @@ -27,18 +27,18 @@ class FileUser implements IUser
/** @var string */
protected $dir = '';

public function setData(int $authId, string $authName, int $authGroup, int $authClass, ?int $authStatus, string $displayName, string $dir): void
public function setUserData(?string $authId, ?string $authName, ?string $authGroup, ?int $authClass, ?int $authStatus, ?string $displayName, ?string $dir): void
{
$this->authId = $authId;
$this->authName = $authName;
$this->authGroup = $authGroup;
$this->authClass = $authClass;
$this->authId = $authId ?? $this->authId;
$this->authName = $authName ?? $this->authName;
$this->authGroup = $authGroup ?? $this->authGroup;
$this->authClass = $authClass ?? $this->authClass;
$this->authStatus = $authStatus;
$this->displayName = $displayName;
$this->dir = $dir;
$this->displayName = $displayName ?? $this->displayName;
$this->dir = $dir ?? $this->dir;
}

public function getAuthId(): int
public function getAuthId(): string
{
return $this->authId;
}
Expand All @@ -48,7 +48,7 @@ public function getAuthName(): string
return $this->authName;
}

public function getGroup(): int
public function getGroup(): string
{
return $this->authGroup;
}
Expand Down
6 changes: 3 additions & 3 deletions php-src/Data/TCerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ trait TCerts
/** @var string */
protected $salt = '';

public function addCertInfo(string $key, string $salt): void
public function addCertInfo(?string $key, ?string $salt): void
{
$this->key = $key;
$this->salt = $salt;
$this->key = $key ?? $this->key;
$this->salt = $salt ?? $this->salt;
}

public function getPubKey(): string
Expand Down
8 changes: 4 additions & 4 deletions php-src/Interfaces/IAccessGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ interface IAccessGroups
public function createGroup(IGroup $group): void;

/**
* @param int $groupId
* @param string $groupId
* @throws AuthException
* @throws LockException
* @return IGroup|null
*/
public function getGroupDataOnly(int $groupId): ?IGroup;
public function getGroupDataOnly(string $groupId): ?IGroup;

/**
* @throws AuthException
Expand All @@ -55,10 +55,10 @@ public function readGroup(): array;
public function updateGroup(IGroup $group): bool;

/**
* @param int $groupId
* @param string $groupId
* @throws AuthException
* @throws LockException
* @return bool
*/
public function deleteGroup(int $groupId): bool;
public function deleteGroup(string $groupId): bool;
}
21 changes: 16 additions & 5 deletions php-src/Interfaces/IGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@
*/
interface IGroup
{
/**
* Fill group; null values will not change
* @param string|null $id
* @param string|null $name
* @param string|null $desc
* @param string|null $authorId
* @param int|null $status
* @param string[]|null $parents
*/
public function setGroupData(?string $id, ?string $name, ?string $desc, ?string $authorId, ?int $status, ?array $parents = []): void;

/**
* ID of group
* @return int
* @return string
*/
public function getGroupId(): int;
public function getGroupId(): string;

/**
* Human-understandable name
Expand All @@ -30,9 +41,9 @@ public function getGroupDesc(): string;

/**
* Who adds it
* @return int
* @return string
*/
public function getGroupAuthorId(): int;
public function getGroupAuthorId(): string;

/**
* User statuses as defined in \kalanis\kw_auth\Interfaces\IUser
Expand All @@ -42,7 +53,7 @@ public function getGroupStatus(): int;

/**
* IDs of parent groups
* @return int[]
* @return string[]
*/
public function getGroupParents(): array;
}
18 changes: 14 additions & 4 deletions php-src/Interfaces/IUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
interface IUser
{
const LOWEST_USER_ID = 1000;
const LOWEST_USER_ID = '1000';
const STATUS_NONE = 'none';

const USER_STATUS_UNKNOWN = null;
Expand All @@ -19,13 +19,23 @@ interface IUser
const USER_STATUS_ONLY_LOGIN = 2;
const USER_STATUS_ONLY_CERT = 3;

public function setData(int $authId, string $authName, int $authGroup, int $authClass, ?int $authStatus, string $displayName, string $dir): void;
/**
* Fill user; null values will not change
* @param string|null $authId
* @param string|null $authName
* @param string|null $authGroup
* @param int|null $authClass
* @param int|null $authStatus
* @param string|null $displayName
* @param string|null $dir
*/
public function setUserData(?string $authId, ?string $authName, ?string $authGroup, ?int $authClass, ?int $authStatus, ?string $displayName, ?string $dir): void;

public function getAuthId(): int;
public function getAuthId(): string;

public function getAuthName(): string;

public function getGroup(): int;
public function getGroup(): string;

public function getClass(): int;

Expand Down
7 changes: 6 additions & 1 deletion php-src/Interfaces/IUserCert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
*/
interface IUserCert extends IUser
{
public function addCertInfo(string $key, string $salt): void;
/**
* Fill certificates; null values will not change
* @param string $key
* @param string $salt
*/
public function addCertInfo(?string $key, ?string $salt): void;

public function getPubSalt(): string;

Expand Down
6 changes: 3 additions & 3 deletions php-src/Methods/Everytime.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class Everytime extends AMethods
public function process(\ArrayAccess $credentials): void
{
$this->loggedUser = new FileUser();
$this->loggedUser->setData(
0,
$this->loggedUser->setUserData(
'0',
'Debug',
0,
'0',
IAccessClasses::CLASS_USER,
null,
'Debug',
Expand Down
14 changes: 7 additions & 7 deletions php-src/Sources/Files/AFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public function getDataOnly(string $userName): ?Interfaces\IUser
protected function getUserClass(array &$line): Interfaces\IUser
{
$user = new FileUser();
$user->setData(
intval($line[static::PW_ID]),
$user->setUserData(
strval($line[static::PW_ID]),
strval($line[static::PW_NAME]),
intval($line[static::PW_GROUP]),
strval($line[static::PW_GROUP]),
intval($line[static::PW_CLASS]),
$this->transformFromStringToInt(strval($line[static::PW_STATUS])),
strval($line[static::PW_DISPLAY]),
Expand Down Expand Up @@ -152,11 +152,11 @@ public function createAccount(Interfaces\IUser $user, string $password): void
$uid++;

$newUserPass = [
static::PW_ID => $uid,
static::PW_ID => strval($uid),
static::PW_NAME => $userName,
static::PW_PASS => $this->mode->hash($password),
static::PW_GROUP => empty($user->getGroup()) ? $uid : $user->getClass() ,
static::PW_CLASS => empty($user->getClass()) ? Interfaces\IAccessClasses::CLASS_USER : $user->getClass() ,
static::PW_GROUP => empty($user->getGroup()) ? $uid : $user->getGroup() ,
static::PW_CLASS => empty($user->getClass()) ? Interfaces\IAccessClasses::CLASS_USER : strval($user->getClass()) ,
static::PW_STATUS => $this->transformFromIntToString($user->getStatus()),
static::PW_DISPLAY => empty($displayName) ? $userName : $displayName,
static::PW_DIR => $directory,
Expand Down Expand Up @@ -209,7 +209,7 @@ public function updateAccount(Interfaces\IUser $user): bool
if ($line[static::PW_NAME] == $userName) {
// REFILL
$line[static::PW_GROUP] = !empty($user->getGroup()) ? $user->getGroup() : $line[static::PW_GROUP] ;
$line[static::PW_CLASS] = !empty($user->getClass()) ? $user->getClass() : $line[static::PW_CLASS] ;
$line[static::PW_CLASS] = !empty($user->getClass()) ? strval($user->getClass()) : $line[static::PW_CLASS] ;
$line[static::PW_STATUS] = $this->transformFromIntToString($user->getStatus());
$line[static::PW_DISPLAY] = !empty($displayName) ? $displayName : $line[static::PW_DISPLAY] ;
$line[static::PW_DIR] = !empty($directory) ? $directory : $line[static::PW_DIR] ;
Expand Down
16 changes: 8 additions & 8 deletions php-src/Sources/Files/AFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public function getDataOnly(string $userName): ?Interfaces\IUser
foreach ($passwordLines as &$line) {
if ($line[static::PW_NAME] == $name) {
$user = $this->getUserClass();
$user->setData(
intval($line[static::PW_ID]),
$user->setUserData(
strval($line[static::PW_ID]),
strval($line[static::PW_NAME]),
intval($line[static::PW_GROUP]),
strval($line[static::PW_GROUP]),
intval($line[static::PW_CLASS]),
$this->transformFromStringToInt(strval($line[static::PW_STATUS])),
strval($line[static::PW_DISPLAY]),
Expand Down Expand Up @@ -219,7 +219,7 @@ public function updateCertKeys(string $userName, ?string $certKey, ?string $cert
if ($line[static::SH_NAME] == $name) {
$changed = true;
$line[static::SH_CERT_KEY] = $certKey ? base64_encode($certKey) : $line[static::SH_CERT_KEY];
$line[static::SH_CERT_SALT] = $certSalt ?: $line[static::SH_CERT_SALT];
$line[static::SH_CERT_SALT] = $certSalt ?? $line[static::SH_CERT_SALT];
}
}

Expand Down Expand Up @@ -319,10 +319,10 @@ public function readAccounts(): array
$result = [];
foreach ($passLines as &$line) {
$record = $this->getUserClass();
$record->setData(
intval($line[static::PW_ID]),
$record->setUserData(
strval($line[static::PW_ID]),
strval($line[static::PW_NAME]),
intval($line[static::PW_GROUP]),
strval($line[static::PW_GROUP]),
intval($line[static::PW_CLASS]),
$this->transformFromStringToInt(strval($line[static::PW_STATUS])),
strval($line[static::PW_DISPLAY]),
Expand Down Expand Up @@ -432,7 +432,7 @@ public function deleteAccount(string $userName): bool
return $changed;
}

protected function checkRest(int $groupId): void
protected function checkRest(string $groupId): void
{
$passLines = $this->openPassword();
foreach ($passLines as &$line) {
Expand Down
2 changes: 1 addition & 1 deletion php-src/Sources/Files/AGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(ILock $lock, array $path, ?IKauTranslations $lang =
$this->path = $path;
}

protected function checkRest(/** @scrutinizer ignore-unused */ int $groupId): void
protected function checkRest(/** @scrutinizer ignore-unused */ string $groupId): void
{
// nothing here
}
Expand Down

0 comments on commit eaba003

Please sign in to comment.