| @@ 142-160 (lines=19) @@ | ||
| 139 | return $stmt->fetchColumn(); |
|
| 140 | } |
|
| 141 | ||
| 142 | public function setVootToken($userId, $vootToken) |
|
| 143 | { |
|
| 144 | $userId = $this->getId($userId); |
|
| 145 | $stmt = $this->db->prepare( |
|
| 146 | <<< 'SQL' |
|
| 147 | INSERT INTO voot_tokens |
|
| 148 | (user_id, voot_token) |
|
| 149 | VALUES |
|
| 150 | (:user_id, :voot_token) |
|
| 151 | SQL |
|
| 152 | ); |
|
| 153 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 154 | $stmt->bindValue(':voot_token', $vootToken, PDO::PARAM_STR); |
|
| 155 | ||
| 156 | $stmt->execute(); |
|
| 157 | ||
| 158 | // XXX deal with errors! |
|
| 159 | return 1 === $stmt->rowCount(); |
|
| 160 | } |
|
| 161 | ||
| 162 | public function hasVootToken($userId) |
|
| 163 | { |
|
| @@ 162-179 (lines=18) @@ | ||
| 159 | return 1 === $stmt->rowCount(); |
|
| 160 | } |
|
| 161 | ||
| 162 | public function hasVootToken($userId) |
|
| 163 | { |
|
| 164 | $userId = $this->getId($userId); |
|
| 165 | $stmt = $this->db->prepare( |
|
| 166 | <<< 'SQL' |
|
| 167 | SELECT |
|
| 168 | COUNT(*) |
|
| 169 | FROM |
|
| 170 | voot_tokens |
|
| 171 | WHERE |
|
| 172 | user_id = :user_id |
|
| 173 | SQL |
|
| 174 | ); |
|
| 175 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 176 | $stmt->execute(); |
|
| 177 | ||
| 178 | return 1 === (int) $stmt->fetchColumn(); |
|
| 179 | } |
|
| 180 | ||
| 181 | public function deleteVootToken($userId) |
|
| 182 | { |
|
| @@ 181-197 (lines=17) @@ | ||
| 178 | return 1 === (int) $stmt->fetchColumn(); |
|
| 179 | } |
|
| 180 | ||
| 181 | public function deleteVootToken($userId) |
|
| 182 | { |
|
| 183 | $userId = $this->getId($userId); |
|
| 184 | $stmt = $this->db->prepare( |
|
| 185 | <<< 'SQL' |
|
| 186 | DELETE FROM |
|
| 187 | voot_tokens |
|
| 188 | WHERE |
|
| 189 | user_id = :user_id |
|
| 190 | SQL |
|
| 191 | ); |
|
| 192 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 193 | ||
| 194 | $stmt->execute(); |
|
| 195 | // XXX error handling! |
|
| 196 | return 1 === $stmt->rowCount(); |
|
| 197 | } |
|
| 198 | ||
| 199 | public function hasTotpSecret($userId) |
|
| 200 | { |
|
| @@ 199-216 (lines=18) @@ | ||
| 196 | return 1 === $stmt->rowCount(); |
|
| 197 | } |
|
| 198 | ||
| 199 | public function hasTotpSecret($userId) |
|
| 200 | { |
|
| 201 | $userId = $this->getId($userId); |
|
| 202 | $stmt = $this->db->prepare( |
|
| 203 | <<< 'SQL' |
|
| 204 | SELECT |
|
| 205 | COUNT(*) |
|
| 206 | FROM |
|
| 207 | totp_secrets |
|
| 208 | WHERE |
|
| 209 | user_id = :user_id |
|
| 210 | SQL |
|
| 211 | ); |
|
| 212 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 213 | $stmt->execute(); |
|
| 214 | ||
| 215 | return 1 === (int) $stmt->fetchColumn(); |
|
| 216 | } |
|
| 217 | ||
| 218 | public function getTotpSecret($userId) |
|
| 219 | { |
|
| @@ 261-278 (lines=18) @@ | ||
| 258 | } |
|
| 259 | } |
|
| 260 | ||
| 261 | public function deleteTotpSecret($userId) |
|
| 262 | { |
|
| 263 | $userId = $this->getId($userId); |
|
| 264 | $stmt = $this->db->prepare( |
|
| 265 | <<< 'SQL' |
|
| 266 | DELETE FROM |
|
| 267 | totp_secrets |
|
| 268 | WHERE |
|
| 269 | user_id = :user_id |
|
| 270 | SQL |
|
| 271 | ); |
|
| 272 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 273 | ||
| 274 | $stmt->execute(); |
|
| 275 | ||
| 276 | // XXX error handling? |
|
| 277 | return 1 === $stmt->rowCount(); |
|
| 278 | } |
|
| 279 | ||
| 280 | public function deleteUser($userId) |
|
| 281 | { |
|
| @@ 280-296 (lines=17) @@ | ||
| 277 | return 1 === $stmt->rowCount(); |
|
| 278 | } |
|
| 279 | ||
| 280 | public function deleteUser($userId) |
|
| 281 | { |
|
| 282 | $userId = $this->getId($userId); |
|
| 283 | $stmt = $this->db->prepare( |
|
| 284 | <<< 'SQL' |
|
| 285 | DELETE FROM |
|
| 286 | users |
|
| 287 | WHERE |
|
| 288 | id = :user_id |
|
| 289 | SQL |
|
| 290 | ); |
|
| 291 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 292 | ||
| 293 | $stmt->execute(); |
|
| 294 | // XXX error handling? |
|
| 295 | return 1 === $stmt->rowCount(); |
|
| 296 | } |
|
| 297 | ||
| 298 | public function addCertificate($userId, $commonName, $displayName, DateTime $validFrom, DateTime $validTo) |
|
| 299 | { |
|
| @@ 404-424 (lines=21) @@ | ||
| 401 | return 1 === $stmt->rowCount(); |
|
| 402 | } |
|
| 403 | ||
| 404 | public function disableUser($userId) |
|
| 405 | { |
|
| 406 | $userId = $this->getId($userId); |
|
| 407 | $stmt = $this->db->prepare( |
|
| 408 | <<< 'SQL' |
|
| 409 | UPDATE |
|
| 410 | users |
|
| 411 | SET |
|
| 412 | is_disabled = 1 |
|
| 413 | WHERE |
|
| 414 | id = :user_id |
|
| 415 | SQL |
|
| 416 | ); |
|
| 417 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 418 | ||
| 419 | $stmt->execute(); |
|
| 420 | ||
| 421 | // XXX it seems on update the rowCount is always 1, even if nothing was |
|
| 422 | // modified? |
|
| 423 | return 1 === $stmt->rowCount(); |
|
| 424 | } |
|
| 425 | ||
| 426 | public function enableUser($userId) |
|
| 427 | { |
|
| @@ 426-446 (lines=21) @@ | ||
| 423 | return 1 === $stmt->rowCount(); |
|
| 424 | } |
|
| 425 | ||
| 426 | public function enableUser($userId) |
|
| 427 | { |
|
| 428 | $userId = $this->getId($userId); |
|
| 429 | $stmt = $this->db->prepare( |
|
| 430 | <<< 'SQL' |
|
| 431 | UPDATE |
|
| 432 | users |
|
| 433 | SET |
|
| 434 | is_disabled = 0 |
|
| 435 | WHERE |
|
| 436 | id = :user_id |
|
| 437 | SQL |
|
| 438 | ); |
|
| 439 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 440 | ||
| 441 | $stmt->execute(); |
|
| 442 | ||
| 443 | // XXX it seems on update the rowCount is always 1, even if nothing was |
|
| 444 | // modified? |
|
| 445 | return 1 === $stmt->rowCount(); |
|
| 446 | } |
|
| 447 | ||
| 448 | public function isDisabledUser($userId) |
|
| 449 | { |
|
| @@ 448-467 (lines=20) @@ | ||
| 445 | return 1 === $stmt->rowCount(); |
|
| 446 | } |
|
| 447 | ||
| 448 | public function isDisabledUser($userId) |
|
| 449 | { |
|
| 450 | $userId = $this->getId($userId); |
|
| 451 | $stmt = $this->db->prepare( |
|
| 452 | <<< 'SQL' |
|
| 453 | SELECT |
|
| 454 | COUNT(*) |
|
| 455 | FROM |
|
| 456 | users |
|
| 457 | WHERE |
|
| 458 | id = :user_id |
|
| 459 | AND |
|
| 460 | is_disabled = 1 |
|
| 461 | SQL |
|
| 462 | ); |
|
| 463 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 464 | $stmt->execute(); |
|
| 465 | ||
| 466 | return 1 === (int) $stmt->fetchColumn(); |
|
| 467 | } |
|
| 468 | ||
| 469 | public function getAllLogEntries() |
|
| 470 | { |
|