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 array $fields = ['email', 'password', 'type', 'active'];
|
||||
protected static array $fields = ['email', 'password', 'type', 'active', 'google_sub'];
|
||||
|
||||
private static array $types = ['user', 'admin'];
|
||||
|
||||
private string $email = '';
|
||||
|
||||
private string $password = '';
|
||||
private ?string $password = null;
|
||||
|
||||
private string $type = 'user';
|
||||
|
||||
private bool $active = false;
|
||||
|
||||
private ?string $googleSub = null;
|
||||
|
||||
public function setEmail(string $email): void
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function setPassword(string $hashedPassword): void
|
||||
public function setPassword(?string $hashedPassword): void
|
||||
{
|
||||
$this->password = $hashedPassword;
|
||||
}
|
||||
@ -45,12 +47,17 @@ class User extends Model implements IUser
|
||||
$this->active = (bool) $active;
|
||||
}
|
||||
|
||||
public function setGoogleSub(?string $googleSub): void
|
||||
{
|
||||
$this->googleSub = $googleSub;
|
||||
}
|
||||
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function getPassword(): string
|
||||
public function getPassword(): ?string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
@ -65,6 +72,11 @@ class User extends Model implements IUser
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
public function getGoogleSub(): ?string
|
||||
{
|
||||
return $this->googleSub;
|
||||
}
|
||||
|
||||
public function hasPermission(int $permission): bool
|
||||
{
|
||||
switch ($permission) {
|
||||
|
@ -25,4 +25,12 @@ class UserRepository
|
||||
|
||||
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