| @@ 49-70 (lines=22) @@ | ||
| 46 | /** |
|
| 47 | * @param Entity\IdentityCollection $collection |
|
| 48 | */ |
|
| 49 | public function fetch(Entity\IdentityCollection $collection) |
|
| 50 | { |
|
| 51 | $table = $this->config['accounts']['identities']; |
|
| 52 | ||
| 53 | $sql = "SELECT identity_id AS id |
|
| 54 | FROM {$table} |
|
| 55 | WHERE status = :status |
|
| 56 | AND user_id = :user |
|
| 57 | AND type = :type"; |
|
| 58 | ||
| 59 | $statement = $this->connection->prepare($sql); |
|
| 60 | ||
| 61 | $statement->bindValue(':user', $collection->getUserId()); |
|
| 62 | $statement->bindValue(':status', $collection->getStatus()); |
|
| 63 | $statement->bindValue(':type', $collection->getType()); |
|
| 64 | ||
| 65 | $statement->execute(); |
|
| 66 | ||
| 67 | foreach ($statement as $parameters) { |
|
| 68 | $collection->addBlueprint($parameters); |
|
| 69 | } |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||
| @@ 20-43 (lines=24) @@ | ||
| 17 | /** |
|
| 18 | * @param Entity\CookieIdentity $entity |
|
| 19 | */ |
|
| 20 | public function exists(Entity\CookieIdentity $entity) |
|
| 21 | { |
|
| 22 | $table = $this->config['accounts']['identities']; |
|
| 23 | ||
| 24 | $sql = "SELECT 1 |
|
| 25 | FROM $table AS Identities |
|
| 26 | WHERE type = :type |
|
| 27 | AND user_id = :user |
|
| 28 | AND identifier = :series |
|
| 29 | AND fingerprint = :fingerprint"; |
|
| 30 | ||
| 31 | $statement = $this->connection->prepare($sql); |
|
| 32 | ||
| 33 | $statement->bindValue(':type', $entity->getType()); |
|
| 34 | $statement->bindValue(':user', $entity->getUserId()); |
|
| 35 | $statement->bindValue(':series', $entity->getSeries()); |
|
| 36 | $statement->bindValue(':fingerprint', $entity->getFingerprint()); |
|
| 37 | ||
| 38 | $statement->execute(); |
|
| 39 | ||
| 40 | $data = $statement->fetch(); |
|
| 41 | ||
| 42 | return empty($data) === false; |
|
| 43 | } |
|
| 44 | ||
| 45 | ||
| 46 | /** |
|
| @@ 115-136 (lines=22) @@ | ||
| 112 | } |
|
| 113 | ||
| 114 | ||
| 115 | private function updateCookie(Entity\CookieIdentity $entity) |
|
| 116 | { |
|
| 117 | $table = $this->config['accounts']['identities']; |
|
| 118 | $active = Entity\Identity::STATUS_ACTIVE; |
|
| 119 | ||
| 120 | $sql = "UPDATE {$table} |
|
| 121 | SET status = :status, |
|
| 122 | hash = :hash, |
|
| 123 | used_on = NOW(), |
|
| 124 | expires_on = FROM_UNIXTIME(:expires) |
|
| 125 | WHERE identity_id = :id |
|
| 126 | AND status = {$active}"; |
|
| 127 | ||
| 128 | $statement = $this->connection->prepare($sql); |
|
| 129 | ||
| 130 | $statement->bindValue(':id', $entity->getId()); |
|
| 131 | $statement->bindValue(':status', $entity->getStatus()); |
|
| 132 | $statement->bindValue(':hash', $entity->getHash()); |
|
| 133 | $statement->bindValue(':expires', $entity->getExpiresOn()); |
|
| 134 | ||
| 135 | $statement->execute(); |
|
| 136 | } |
|
| 137 | } |
|
| 138 | ||
| @@ 46-75 (lines=30) @@ | ||
| 43 | /** |
|
| 44 | * @param Entity\EmailIdentity $entity |
|
| 45 | */ |
|
| 46 | public function fetch(Entity\EmailIdentity $entity) |
|
| 47 | { |
|
| 48 | $table = $this->config['accounts']['identities']; |
|
| 49 | ||
| 50 | $sql = "SELECT identity_id AS id, |
|
| 51 | user_id AS userId, |
|
| 52 | hash AS hash, |
|
| 53 | status AS status, |
|
| 54 | token AS token, |
|
| 55 | token_action AS tokenAction, |
|
| 56 | UNIX_TIMESTAMP(token_expires_on) AS tokenEndOfLife |
|
| 57 | FROM $table |
|
| 58 | WHERE type = :type |
|
| 59 | AND fingerprint = :fingerprint |
|
| 60 | AND identifier = :identifier"; |
|
| 61 | ||
| 62 | $statement = $this->connection->prepare($sql); |
|
| 63 | ||
| 64 | $statement->bindValue(':type', $entity->getType()); |
|
| 65 | $statement->bindValue(':identifier', $entity->getIdentifier()); |
|
| 66 | $statement->bindValue(':fingerprint', $entity->getFingerprint()); |
|
| 67 | ||
| 68 | $statement->execute(); |
|
| 69 | ||
| 70 | $data = $statement->fetch(); |
|
| 71 | ||
| 72 | if ($data) { |
|
| 73 | $this->applyValues($entity, $data); |
|
| 74 | } |
|
| 75 | } |
|
| 76 | ||
| 77 | ||
| 78 | /** |
|
| @@ 38-65 (lines=28) @@ | ||
| 35 | /** |
|
| 36 | * @param Entity\Identity $entity |
|
| 37 | */ |
|
| 38 | public function fetch(Entity\Identity $entity) |
|
| 39 | { |
|
| 40 | $table = $this->config['accounts']['identities']; |
|
| 41 | ||
| 42 | $sql = "SELECT identity_id AS id, |
|
| 43 | user_id AS userId, |
|
| 44 | status AS status, |
|
| 45 | hash AS hash, |
|
| 46 | UNIX_TIMESTAMP(token_expires_on) AS tokenEndOfLife |
|
| 47 | FROM $table |
|
| 48 | WHERE token = :token |
|
| 49 | AND token_action = :action |
|
| 50 | AND token_expires_on > FROM_UNIXTIME(:expires)"; |
|
| 51 | ||
| 52 | $statement = $this->connection->prepare($sql); |
|
| 53 | ||
| 54 | $statement->bindValue(':token', $entity->getToken()); |
|
| 55 | $statement->bindValue(':action', $entity->getTokenAction()); |
|
| 56 | $statement->bindValue(':expires', $entity->getTokenEndOfLife()); |
|
| 57 | ||
| 58 | $statement->execute(); |
|
| 59 | ||
| 60 | $data = $statement->fetch(); |
|
| 61 | ||
| 62 | if ($data) { |
|
| 63 | $this->applyValues($entity, $data); |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| 67 | ||
| 68 | /** |
|