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