| @@ 220-253 (lines=34) @@ | ||
| 217 | }); |
|
| 218 | } |
|
| 219 | ||
| 220 | bcrypt.hash(password, 10, function(err, hash) { |
|
| 221 | if (err) { |
|
| 222 | return res.status(500).json({ |
|
| 223 | errors: { |
|
| 224 | status: 500, |
|
| 225 | source: "/register", |
|
| 226 | title: "bcrypt error", |
|
| 227 | detail: "bcrypt error" |
|
| 228 | } |
|
| 229 | }); |
|
| 230 | } |
|
| 231 | ||
| 232 | db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)", |
|
| 233 | apiKey, |
|
| 234 | email, |
|
| 235 | hash, (err) => { |
|
| 236 | if (err) { |
|
| 237 | return res.status(500).json({ |
|
| 238 | errors: { |
|
| 239 | status: 500, |
|
| 240 | source: "/register", |
|
| 241 | title: "Database error", |
|
| 242 | detail: err.message |
|
| 243 | } |
|
| 244 | }); |
|
| 245 | } |
|
| 246 | ||
| 247 | res.status(201).json({ |
|
| 248 | data: { |
|
| 249 | message: "User successfully registered." |
|
| 250 | } |
|
| 251 | }); |
|
| 252 | }); |
|
| 253 | }); |
|
| 254 | } |
|
| 255 | ||
| 256 | function checkToken(req, res, next) { |
|
| @@ 259-292 (lines=34) @@ | ||
| 256 | }); |
|
| 257 | } |
|
| 258 | ||
| 259 | bcrypt.hash(password, 10, function(err, hash) { |
|
| 260 | if (err) { |
|
| 261 | return res.status(500).json({ |
|
| 262 | errors: { |
|
| 263 | status: 500, |
|
| 264 | source: "/register", |
|
| 265 | title: "bcrypt error", |
|
| 266 | detail: "bcrypt error" |
|
| 267 | } |
|
| 268 | }); |
|
| 269 | } |
|
| 270 | ||
| 271 | db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)", |
|
| 272 | apiKey, |
|
| 273 | email, |
|
| 274 | hash, (err) => { |
|
| 275 | if (err) { |
|
| 276 | return res.status(500).json({ |
|
| 277 | errors: { |
|
| 278 | status: 500, |
|
| 279 | source: "/register", |
|
| 280 | title: "Database error", |
|
| 281 | detail: err.message |
|
| 282 | } |
|
| 283 | }); |
|
| 284 | } |
|
| 285 | ||
| 286 | return res.status(201).json({ |
|
| 287 | data: { |
|
| 288 | message: "User successfully registered." |
|
| 289 | } |
|
| 290 | }); |
|
| 291 | }); |
|
| 292 | }); |
|
| 293 | }, |
|
| 294 | ||
| 295 | checkToken: function(req, res, next) { |
|