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