@@ 22-26 (lines=5) @@ | ||
19 | * @return value string Value |
|
20 | **/ |
|
21 | public function getToken($strToken, $strType=NULL) { |
|
22 | if (empty($strType) || ! $iToken_id = $this->tokentype->getTypeId($strType)) { |
|
23 | $this->setErrorMessage('Invalid token type: ' . $strType); |
|
24 | return false; |
|
25 | } |
|
26 | $stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE token = ? LIMIT 1"); |
|
27 | if ($stmt && $stmt->bind_param('s', $strToken) && $stmt->execute() && $result = $stmt->get_result()) |
|
28 | return $result->fetch_assoc(); |
|
29 | return $this->sqlError(); |
|
@@ 74-78 (lines=5) @@ | ||
71 | * @return mixed Number of rows on success, false on failure |
|
72 | */ |
|
73 | public function doesTokenExist($strType=NULL, $account_id=NULL) { |
|
74 | if (!$iToken_id = $this->tokentype->getTypeId($strType)) { |
|
75 | $this->setErrorMessage('Invalid token type: ' . $strType); |
|
76 | return false; |
|
77 | } |
|
78 | $stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE account_id = ? AND type = ? LIMIT 1"); |
|
79 | if ($stmt && $stmt->bind_param('ii', $account_id, $iToken_id) && $stmt->execute()) |
|
80 | return $stmt->get_result()->num_rows; |
|
81 | return $this->sqlError(); |
|
@@ 91-95 (lines=5) @@ | ||
88 | * @return mixed Token string on success, false on failure |
|
89 | **/ |
|
90 | public function createToken($strType, $account_id=NULL) { |
|
91 | if (!$iToken_id = $this->tokentype->getTypeId($strType)) { |
|
92 | $this->setErrorMessage('Invalid token type: ' . $strType); |
|
93 | return false; |
|
94 | } |
|
95 | $strToken = bin2hex(openssl_random_pseudo_bytes(32)); |
|
96 | $stmt = $this->mysqli->prepare(" |
|
97 | INSERT INTO $this->table (token, type, account_id) |
|
98 | VALUES (?, ?, ?) |