MAPG-69 add new field to User
This commit is contained in:
parent
99c72d99be
commit
7ba11f34cc
@ -0,0 +1,8 @@
|
|||||||
|
ALTER TABLE
|
||||||
|
`users`
|
||||||
|
ADD
|
||||||
|
`google_sub` varchar(255) CHARACTER SET ascii COLLATE ascii_bin NULL DEFAULT NULL,
|
||||||
|
ADD
|
||||||
|
UNIQUE `google_sub` (`google_sub`),
|
||||||
|
MODIFY
|
||||||
|
`password` varchar(60) NULL DEFAULT NULL;
|
@ -6,24 +6,26 @@ class User extends Model implements IUser
|
|||||||
{
|
{
|
||||||
protected static string $table = 'users';
|
protected static string $table = 'users';
|
||||||
|
|
||||||
protected static array $fields = ['email', 'password', 'type', 'active'];
|
protected static array $fields = ['email', 'password', 'type', 'active', 'google_sub'];
|
||||||
|
|
||||||
private static array $types = ['user', 'admin'];
|
private static array $types = ['user', 'admin'];
|
||||||
|
|
||||||
private string $email = '';
|
private string $email = '';
|
||||||
|
|
||||||
private string $password = '';
|
private ?string $password = null;
|
||||||
|
|
||||||
private string $type = 'user';
|
private string $type = 'user';
|
||||||
|
|
||||||
private bool $active = false;
|
private bool $active = false;
|
||||||
|
|
||||||
|
private ?string $googleSub = null;
|
||||||
|
|
||||||
public function setEmail(string $email): void
|
public function setEmail(string $email): void
|
||||||
{
|
{
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPassword(string $hashedPassword): void
|
public function setPassword(?string $hashedPassword): void
|
||||||
{
|
{
|
||||||
$this->password = $hashedPassword;
|
$this->password = $hashedPassword;
|
||||||
}
|
}
|
||||||
@ -45,12 +47,17 @@ class User extends Model implements IUser
|
|||||||
$this->active = (bool) $active;
|
$this->active = (bool) $active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setGoogleSub(?string $googleSub): void
|
||||||
|
{
|
||||||
|
$this->googleSub = $googleSub;
|
||||||
|
}
|
||||||
|
|
||||||
public function getEmail(): string
|
public function getEmail(): string
|
||||||
{
|
{
|
||||||
return $this->email;
|
return $this->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPassword(): string
|
public function getPassword(): ?string
|
||||||
{
|
{
|
||||||
return $this->password;
|
return $this->password;
|
||||||
}
|
}
|
||||||
@ -65,6 +72,11 @@ class User extends Model implements IUser
|
|||||||
return $this->active;
|
return $this->active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getGoogleSub(): ?string
|
||||||
|
{
|
||||||
|
return $this->googleSub;
|
||||||
|
}
|
||||||
|
|
||||||
public function hasPermission(int $permission): bool
|
public function hasPermission(int $permission): bool
|
||||||
{
|
{
|
||||||
switch ($permission) {
|
switch ($permission) {
|
||||||
|
@ -25,4 +25,12 @@ class UserRepository
|
|||||||
|
|
||||||
return $this->pdm->selectFromDb($select, User::class);
|
return $this->pdm->selectFromDb($select, User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getByGoogleSub(string $sub): ?User
|
||||||
|
{
|
||||||
|
$select = new Select(\Container::$dbConnection);
|
||||||
|
$select->where('google_sub', '=', $sub);
|
||||||
|
|
||||||
|
return $this->pdm->selectFromDb($select, User::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user