@@ 99-131 (lines=33) @@ | ||
96 | getUniqueAPIKey: function(res, path, email) { |
|
97 | const apiKey = hat(); |
|
98 | ||
99 | db.get("SELECT key FROM apikeys WHERE key = ?", apiKey, (err, row) => { |
|
100 | if (err) { |
|
101 | return res.status(401).json({ |
|
102 | errors: { |
|
103 | status: 401, |
|
104 | source: path, |
|
105 | title: "Database error", |
|
106 | detail: err.message |
|
107 | } |
|
108 | }); |
|
109 | } |
|
110 | ||
111 | if (row === undefined) { |
|
112 | db.run("INSERT INTO apikeys (key, email) VALUES (?, ?)", |
|
113 | apiKey, |
|
114 | email, (err) => { |
|
115 | if (err) { |
|
116 | return res.status(401).json({ |
|
117 | errors: { |
|
118 | status: 401, |
|
119 | source: path, |
|
120 | title: "Database error", |
|
121 | detail: err.message |
|
122 | } |
|
123 | }); |
|
124 | } |
|
125 | ||
126 | return res.json({ data: { key: apiKey }}); |
|
127 | }); |
|
128 | } else { |
|
129 | return auth.getUniqueAPIKey(res, email); |
|
130 | } |
|
131 | }); |
|
132 | }, |
|
133 | ||
134 | login: function(res, body) { |
@@ 79-111 (lines=33) @@ | ||
76 | function getUniqueAPIKey(res, path, email) { |
|
77 | const apiKey = hat(); |
|
78 | ||
79 | db.get("SELECT key FROM apikeys WHERE key = ?", apiKey, (err, row) => { |
|
80 | if (err) { |
|
81 | return res.status(401).json({ |
|
82 | errors: { |
|
83 | status: 401, |
|
84 | source: path, |
|
85 | title: "Database error", |
|
86 | detail: err.message |
|
87 | } |
|
88 | }); |
|
89 | } |
|
90 | ||
91 | if (row === undefined) { |
|
92 | db.run("INSERT INTO apikeys (key, email) VALUES (?, ?)", |
|
93 | apiKey, |
|
94 | email, (err) => { |
|
95 | if (err) { |
|
96 | return res.status(401).json({ |
|
97 | errors: { |
|
98 | status: 401, |
|
99 | source: path, |
|
100 | title: "Database error", |
|
101 | detail: err.message |
|
102 | } |
|
103 | }); |
|
104 | } |
|
105 | ||
106 | res.json({ data: { key: apiKey }}); |
|
107 | }); |
|
108 | } else { |
|
109 | getUniqueAPIKey(res, email); |
|
110 | } |
|
111 | }); |
|
112 | } |
|
113 | ||
114 | function login(res, body) { |