| @@ 296-316 (lines=21) @@ | ||
| 293 | return 1 === $stmt->rowCount(); |
|
| 294 | } |
|
| 295 | ||
| 296 | public function addCertificate($userId, $commonName, $displayName, $validFrom, $validTo) |
|
| 297 | { |
|
| 298 | $userId = $this->getId($userId); |
|
| 299 | $stmt = $this->db->prepare( |
|
| 300 | <<< 'SQL' |
|
| 301 | INSERT INTO certificates |
|
| 302 | (common_name, user_id, display_name, valid_from, valid_to) |
|
| 303 | VALUES |
|
| 304 | (:common_name, :user_id, :display_name, :valid_from, :valid_to) |
|
| 305 | SQL |
|
| 306 | ); |
|
| 307 | $stmt->bindValue(':common_name', $commonName, PDO::PARAM_STR); |
|
| 308 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 309 | $stmt->bindValue(':display_name', $displayName, PDO::PARAM_STR); |
|
| 310 | $stmt->bindValue(':valid_from', $validFrom, PDO::PARAM_INT); |
|
| 311 | $stmt->bindValue(':valid_to', $validTo, PDO::PARAM_INT); |
|
| 312 | ||
| 313 | $stmt->execute(); |
|
| 314 | // XXX |
|
| 315 | return 1 === $stmt->rowCount(); |
|
| 316 | } |
|
| 317 | ||
| 318 | public function getCertificates($userId) |
|
| 319 | { |
|
| @@ 496-524 (lines=29) @@ | ||
| 493 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 494 | } |
|
| 495 | ||
| 496 | public function clientConnect($profileId, $commonName, $ip4, $ip6, $connectedAt) |
|
| 497 | { |
|
| 498 | // this query is so complex, because we want to store the user_id in the |
|
| 499 | // log as well, not just the common_name... the user may delete the |
|
| 500 | // certificate, or the user account may be deleted... |
|
| 501 | $stmt = $this->db->prepare( |
|
| 502 | <<< 'SQL' |
|
| 503 | INSERT INTO connection_log |
|
| 504 | ( |
|
| 505 | user_id, |
|
| 506 | profile_id, |
|
| 507 | common_name, |
|
| 508 | ip4, |
|
| 509 | ip6, |
|
| 510 | connected_at |
|
| 511 | ) |
|
| 512 | VALUES |
|
| 513 | ( |
|
| 514 | ( |
|
| 515 | SELECT |
|
| 516 | u.user_id |
|
| 517 | FROM |
|
| 518 | users u, certificates c |
|
| 519 | WHERE |
|
| 520 | u.id = c.user_id |
|
| 521 | AND |
|
| 522 | c.common_name = :common_name |
|
| 523 | ), |
|
| 524 | :profile_id, |
|
| 525 | :common_name, |
|
| 526 | :ip4, |
|
| 527 | :ip6, |
|
| @@ 781-801 (lines=21) @@ | ||
| 778 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 779 | } |
|
| 780 | ||
| 781 | public function addUserMessage($userId, $type, $message, DateTime $dateTime) |
|
| 782 | { |
|
| 783 | $userId = $this->getId($userId); |
|
| 784 | ||
| 785 | $stmt = $this->db->prepare( |
|
| 786 | <<< 'SQL' |
|
| 787 | INSERT INTO user_messages |
|
| 788 | (user_id, type, message, date_time) |
|
| 789 | VALUES |
|
| 790 | (:user_id, :type, :message, :date_time) |
|
| 791 | SQL |
|
| 792 | ); |
|
| 793 | ||
| 794 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 795 | $stmt->bindValue(':type', $type, PDO::PARAM_STR); |
|
| 796 | $stmt->bindValue(':message', $message, PDO::PARAM_STR); |
|
| 797 | $stmt->bindValue(':date_time', $dateTime->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 798 | $stmt->execute(); |
|
| 799 | ||
| 800 | return 1 === $stmt->rowCount(); |
|
| 801 | } |
|
| 802 | ||
| 803 | public function init() |
|
| 804 | { |
|