|
@@ -48,12 +48,19 @@ class UserModel
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function isEmailActive(string $email): bool
|
|
|
|
|
+ {
|
|
|
|
|
+ $stmt = $this->pdo->prepare('SELECT 1 FROM "user" WHERE user_email = :email AND user_flag = \'a\'');
|
|
|
|
|
+ $stmt->execute(['email' => $email]);
|
|
|
|
|
+ return (bool)$stmt->fetchColumn();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function createUser(array $data, string $flag = 'a')
|
|
public function createUser(array $data, string $flag = 'a')
|
|
|
{
|
|
{
|
|
|
// Verifica se email já existe
|
|
// Verifica se email já existe
|
|
|
- $stmt = $this->pdo->prepare('SELECT user_id FROM "user" WHERE user_email = :email');
|
|
|
|
|
|
|
+ $stmt = $this->pdo->prepare('SELECT 1 FROM "user" WHERE user_email = :email AND user_flag = \'a\'');
|
|
|
$stmt->execute(['email' => $data['email']]);
|
|
$stmt->execute(['email' => $data['email']]);
|
|
|
- if ($stmt->fetch()) {
|
|
|
|
|
|
|
+ if ($stmt->fetchColumn()) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -169,14 +176,15 @@ class UserModel
|
|
|
|
|
|
|
|
public function deleteUserById(int $userId, int $companyId): bool
|
|
public function deleteUserById(int $userId, int $companyId): bool
|
|
|
{
|
|
{
|
|
|
- $stmt = $this->pdo->prepare("DELETE FROM \"user\" WHERE user_id = :user_id AND company_id = :company_id");
|
|
|
|
|
- return $stmt->execute(['user_id' => $userId, 'company_id' => $companyId]);
|
|
|
|
|
|
|
+ $stmt = $this->pdo->prepare("UPDATE \"user\" SET user_flag = 'd' WHERE user_id = :user_id AND company_id = :company_id AND user_flag = 'a'");
|
|
|
|
|
+ $stmt->execute(['user_id' => $userId, 'company_id' => $companyId]);
|
|
|
|
|
+ return $stmt->rowCount() > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function updateEmail(int $userId, string $newEmail): bool
|
|
public function updateEmail(int $userId, string $newEmail): bool
|
|
|
{
|
|
{
|
|
|
// check duplicate
|
|
// check duplicate
|
|
|
- $chk = $this->pdo->prepare('SELECT 1 FROM "user" WHERE user_email = :email AND user_id <> :uid');
|
|
|
|
|
|
|
+ $chk = $this->pdo->prepare('SELECT 1 FROM "user" WHERE user_email = :email AND user_id <> :uid AND user_flag = \'a\'');
|
|
|
$chk->execute(['email' => $newEmail, 'uid' => $userId]);
|
|
$chk->execute(['email' => $newEmail, 'uid' => $userId]);
|
|
|
if ($chk->fetchColumn()) {
|
|
if ($chk->fetchColumn()) {
|
|
|
return false;
|
|
return false;
|