| @@ 40-64 (lines=25) @@ | ||
| 37 | }, |
|
| 38 | ||
| 39 | isValidAPIKey: function(apiKey, next, path, res) { |
|
| 40 | db.get("SELECT email FROM apikeys WHERE key = ?", apiKey, (err, row) => { |
|
| 41 | if (err) { |
|
| 42 | return res.status(500).json({ |
|
| 43 | errors: { |
|
| 44 | status: 500, |
|
| 45 | source: path, |
|
| 46 | title: "Database error", |
|
| 47 | detail: err.message |
|
| 48 | } |
|
| 49 | }); |
|
| 50 | } |
|
| 51 | ||
| 52 | if (row !== undefined) { |
|
| 53 | return next(); |
|
| 54 | } |
|
| 55 | ||
| 56 | return res.status(401).json({ |
|
| 57 | errors: { |
|
| 58 | status: 401, |
|
| 59 | source: path, |
|
| 60 | title: "Valid API key", |
|
| 61 | detail: "No valid API key provided." |
|
| 62 | } |
|
| 63 | }); |
|
| 64 | }); |
|
| 65 | }, |
|
| 66 | ||
| 67 | getNewAPIKey: function(res, email) { |
|
| @@ 13-37 (lines=25) @@ | ||
| 10 | ||
| 11 | module.exports = (function () { |
|
| 12 | function isValidAPIKey(apiKey, next, path, res) { |
|
| 13 | db.get("SELECT email FROM apikeys WHERE key = ?", apiKey, (err, row) => { |
|
| 14 | if (err) { |
|
| 15 | return res.status(500).json({ |
|
| 16 | errors: { |
|
| 17 | status: 500, |
|
| 18 | source: path, |
|
| 19 | title: "Database error", |
|
| 20 | detail: err.message |
|
| 21 | } |
|
| 22 | }); |
|
| 23 | } |
|
| 24 | ||
| 25 | if (row !== undefined) { |
|
| 26 | return next(); |
|
| 27 | } |
|
| 28 | ||
| 29 | res.status(401).json({ |
|
| 30 | errors: { |
|
| 31 | status: 401, |
|
| 32 | source: path, |
|
| 33 | title: "Valid API key", |
|
| 34 | detail: "No valid API key provided." |
|
| 35 | } |
|
| 36 | }); |
|
| 37 | }); |
|
| 38 | } |
|
| 39 | ||
| 40 | function getNewAPIKey(res, path, email) { |
|