| @@ 92-109 (lines=18) @@ | ||
| 89 | return $stmt->fetch(PDO::FETCH_ASSOC); |
|
| 90 | } |
|
| 91 | ||
| 92 | public function getVootToken($userId) |
|
| 93 | { |
|
| 94 | $this->addUser($userId); |
|
| 95 | $stmt = $this->db->prepare( |
|
| 96 | <<< 'SQL' |
|
| 97 | SELECT |
|
| 98 | voot_token |
|
| 99 | FROM |
|
| 100 | voot_tokens |
|
| 101 | WHERE |
|
| 102 | user_id = :user_id |
|
| 103 | SQL |
|
| 104 | ); |
|
| 105 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 106 | $stmt->execute(); |
|
| 107 | ||
| 108 | return $stmt->fetchColumn(); |
|
| 109 | } |
|
| 110 | ||
| 111 | public function setVootToken($userId, $vootToken) |
|
| 112 | { |
|
| @@ 131-148 (lines=18) @@ | ||
| 128 | return 1 === $stmt->rowCount(); |
|
| 129 | } |
|
| 130 | ||
| 131 | public function hasVootToken($userId) |
|
| 132 | { |
|
| 133 | $this->addUser($userId); |
|
| 134 | $stmt = $this->db->prepare( |
|
| 135 | <<< 'SQL' |
|
| 136 | SELECT |
|
| 137 | COUNT(*) |
|
| 138 | FROM |
|
| 139 | voot_tokens |
|
| 140 | WHERE |
|
| 141 | user_id = :user_id |
|
| 142 | SQL |
|
| 143 | ); |
|
| 144 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 145 | $stmt->execute(); |
|
| 146 | ||
| 147 | return 1 === (int) $stmt->fetchColumn(); |
|
| 148 | } |
|
| 149 | ||
| 150 | public function deleteVootToken($userId) |
|
| 151 | { |
|
| @@ 150-166 (lines=17) @@ | ||
| 147 | return 1 === (int) $stmt->fetchColumn(); |
|
| 148 | } |
|
| 149 | ||
| 150 | public function deleteVootToken($userId) |
|
| 151 | { |
|
| 152 | $this->addUser($userId); |
|
| 153 | $stmt = $this->db->prepare( |
|
| 154 | <<< 'SQL' |
|
| 155 | DELETE FROM |
|
| 156 | voot_tokens |
|
| 157 | WHERE |
|
| 158 | user_id = :user_id |
|
| 159 | SQL |
|
| 160 | ); |
|
| 161 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 162 | ||
| 163 | $stmt->execute(); |
|
| 164 | // XXX error handling! |
|
| 165 | return 1 === $stmt->rowCount(); |
|
| 166 | } |
|
| 167 | ||
| 168 | public function hasTotpSecret($userId) |
|
| 169 | { |
|
| @@ 168-185 (lines=18) @@ | ||
| 165 | return 1 === $stmt->rowCount(); |
|
| 166 | } |
|
| 167 | ||
| 168 | public function hasTotpSecret($userId) |
|
| 169 | { |
|
| 170 | $this->addUser($userId); |
|
| 171 | $stmt = $this->db->prepare( |
|
| 172 | <<< 'SQL' |
|
| 173 | SELECT |
|
| 174 | COUNT(*) |
|
| 175 | FROM |
|
| 176 | totp_secrets |
|
| 177 | WHERE |
|
| 178 | user_id = :user_id |
|
| 179 | SQL |
|
| 180 | ); |
|
| 181 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 182 | $stmt->execute(); |
|
| 183 | ||
| 184 | return 1 === (int) $stmt->fetchColumn(); |
|
| 185 | } |
|
| 186 | ||
| 187 | public function getTotpSecret($userId) |
|
| 188 | { |
|
| @@ 187-204 (lines=18) @@ | ||
| 184 | return 1 === (int) $stmt->fetchColumn(); |
|
| 185 | } |
|
| 186 | ||
| 187 | public function getTotpSecret($userId) |
|
| 188 | { |
|
| 189 | $this->addUser($userId); |
|
| 190 | $stmt = $this->db->prepare( |
|
| 191 | <<< 'SQL' |
|
| 192 | SELECT |
|
| 193 | totp_secret |
|
| 194 | FROM |
|
| 195 | totp_secrets |
|
| 196 | WHERE |
|
| 197 | user_id = :user_id |
|
| 198 | SQL |
|
| 199 | ); |
|
| 200 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 201 | $stmt->execute(); |
|
| 202 | ||
| 203 | return $stmt->fetchColumn(); |
|
| 204 | } |
|
| 205 | ||
| 206 | public function setTotpSecret($userId, $totpSecret) |
|
| 207 | { |
|
| @@ 230-247 (lines=18) @@ | ||
| 227 | } |
|
| 228 | } |
|
| 229 | ||
| 230 | public function deleteTotpSecret($userId) |
|
| 231 | { |
|
| 232 | $this->addUser($userId); |
|
| 233 | $stmt = $this->db->prepare( |
|
| 234 | <<< 'SQL' |
|
| 235 | DELETE FROM |
|
| 236 | totp_secrets |
|
| 237 | WHERE |
|
| 238 | user_id = :user_id |
|
| 239 | SQL |
|
| 240 | ); |
|
| 241 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 242 | ||
| 243 | $stmt->execute(); |
|
| 244 | ||
| 245 | // XXX error handling? |
|
| 246 | return 1 === $stmt->rowCount(); |
|
| 247 | } |
|
| 248 | ||
| 249 | public function deleteUser($userId) |
|
| 250 | { |
|
| @@ 249-265 (lines=17) @@ | ||
| 246 | return 1 === $stmt->rowCount(); |
|
| 247 | } |
|
| 248 | ||
| 249 | public function deleteUser($userId) |
|
| 250 | { |
|
| 251 | $this->addUser($userId); |
|
| 252 | $stmt = $this->db->prepare( |
|
| 253 | <<< 'SQL' |
|
| 254 | DELETE FROM |
|
| 255 | users |
|
| 256 | WHERE |
|
| 257 | user_id = :user_id |
|
| 258 | SQL |
|
| 259 | ); |
|
| 260 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 261 | ||
| 262 | $stmt->execute(); |
|
| 263 | // XXX error handling? |
|
| 264 | return 1 === $stmt->rowCount(); |
|
| 265 | } |
|
| 266 | ||
| 267 | public function addCertificate($userId, $commonName, $displayName, DateTime $validFrom, DateTime $validTo) |
|
| 268 | { |
|
| @@ 373-393 (lines=21) @@ | ||
| 370 | return 1 === $stmt->rowCount(); |
|
| 371 | } |
|
| 372 | ||
| 373 | public function disableUser($userId) |
|
| 374 | { |
|
| 375 | $this->addUser($userId); |
|
| 376 | $stmt = $this->db->prepare( |
|
| 377 | <<< 'SQL' |
|
| 378 | UPDATE |
|
| 379 | users |
|
| 380 | SET |
|
| 381 | is_disabled = 1 |
|
| 382 | WHERE |
|
| 383 | user_id = :user_id |
|
| 384 | SQL |
|
| 385 | ); |
|
| 386 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 387 | ||
| 388 | $stmt->execute(); |
|
| 389 | ||
| 390 | // XXX it seems on update the rowCount is always 1, even if nothing was |
|
| 391 | // modified? |
|
| 392 | return 1 === $stmt->rowCount(); |
|
| 393 | } |
|
| 394 | ||
| 395 | public function enableUser($userId) |
|
| 396 | { |
|
| @@ 395-415 (lines=21) @@ | ||
| 392 | return 1 === $stmt->rowCount(); |
|
| 393 | } |
|
| 394 | ||
| 395 | public function enableUser($userId) |
|
| 396 | { |
|
| 397 | $this->addUser($userId); |
|
| 398 | $stmt = $this->db->prepare( |
|
| 399 | <<< 'SQL' |
|
| 400 | UPDATE |
|
| 401 | users |
|
| 402 | SET |
|
| 403 | is_disabled = 0 |
|
| 404 | WHERE |
|
| 405 | user_id = :user_id |
|
| 406 | SQL |
|
| 407 | ); |
|
| 408 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 409 | ||
| 410 | $stmt->execute(); |
|
| 411 | ||
| 412 | // XXX it seems on update the rowCount is always 1, even if nothing was |
|
| 413 | // modified? |
|
| 414 | return 1 === $stmt->rowCount(); |
|
| 415 | } |
|
| 416 | ||
| 417 | public function isDisabledUser($userId) |
|
| 418 | { |
|
| @@ 417-436 (lines=20) @@ | ||
| 414 | return 1 === $stmt->rowCount(); |
|
| 415 | } |
|
| 416 | ||
| 417 | public function isDisabledUser($userId) |
|
| 418 | { |
|
| 419 | $this->addUser($userId); |
|
| 420 | $stmt = $this->db->prepare( |
|
| 421 | <<< 'SQL' |
|
| 422 | SELECT |
|
| 423 | COUNT(*) |
|
| 424 | FROM |
|
| 425 | users |
|
| 426 | WHERE |
|
| 427 | user_id = :user_id |
|
| 428 | AND |
|
| 429 | is_disabled = 1 |
|
| 430 | SQL |
|
| 431 | ); |
|
| 432 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 433 | $stmt->execute(); |
|
| 434 | ||
| 435 | return 1 === (int) $stmt->fetchColumn(); |
|
| 436 | } |
|
| 437 | ||
| 438 | public function getAllLogEntries() |
|
| 439 | { |
|
| @@ 575-592 (lines=18) @@ | ||
| 572 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 573 | } |
|
| 574 | ||
| 575 | public function getTotpAttemptCount($userId) |
|
| 576 | { |
|
| 577 | $this->addUser($userId); |
|
| 578 | $stmt = $this->db->prepare( |
|
| 579 | <<< 'SQL' |
|
| 580 | SELECT |
|
| 581 | COUNT(*) |
|
| 582 | FROM |
|
| 583 | totp_log |
|
| 584 | WHERE user_id = :user_id |
|
| 585 | SQL |
|
| 586 | ); |
|
| 587 | ||
| 588 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 589 | $stmt->execute(); |
|
| 590 | ||
| 591 | return (int) $stmt->fetchColumn(); |
|
| 592 | } |
|
| 593 | ||
| 594 | public function recordTotpKey($userId, $totpKey) |
|
| 595 | { |
|
| @@ 724-744 (lines=21) @@ | ||
| 721 | return 1 === $stmt->rowCount(); |
|
| 722 | } |
|
| 723 | ||
| 724 | public function userMessages($userId) |
|
| 725 | { |
|
| 726 | $this->addUser($userId); |
|
| 727 | $stmt = $this->db->prepare( |
|
| 728 | <<< 'SQL' |
|
| 729 | SELECT |
|
| 730 | id, type, message, date_time |
|
| 731 | FROM |
|
| 732 | user_messages |
|
| 733 | WHERE |
|
| 734 | user_id = :user_id |
|
| 735 | ORDER BY |
|
| 736 | date_time DESC |
|
| 737 | SQL |
|
| 738 | ); |
|
| 739 | ||
| 740 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 741 | $stmt->execute(); |
|
| 742 | ||
| 743 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 744 | } |
|
| 745 | ||
| 746 | public function addUserMessage($userId, $type, $message) |
|
| 747 | { |
|