| @@ 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) { |
|
| @@ 353-386 (lines=34) @@ | ||
| 350 | }); |
|
| 351 | } |
|
| 352 | ||
| 353 | bcrypt.hash(password, 10, function(err, hash) { |
|
| 354 | if (err) { |
|
| 355 | return res.status(500).json({ |
|
| 356 | errors: { |
|
| 357 | status: 500, |
|
| 358 | source: "/register", |
|
| 359 | title: "bcrypt error", |
|
| 360 | detail: "bcrypt error" |
|
| 361 | } |
|
| 362 | }); |
|
| 363 | } |
|
| 364 | ||
| 365 | db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)", |
|
| 366 | apiKey, |
|
| 367 | email, |
|
| 368 | hash, (err) => { |
|
| 369 | if (err) { |
|
| 370 | return res.status(500).json({ |
|
| 371 | errors: { |
|
| 372 | status: 500, |
|
| 373 | source: "/register", |
|
| 374 | title: "Database error", |
|
| 375 | detail: err.message |
|
| 376 | } |
|
| 377 | }); |
|
| 378 | } |
|
| 379 | ||
| 380 | return res.status(201).json({ |
|
| 381 | data: { |
|
| 382 | message: "User successfully registered." |
|
| 383 | } |
|
| 384 | }); |
|
| 385 | }); |
|
| 386 | }); |
|
| 387 | }, |
|
| 388 | ||
| 389 | checkToken: function(req, res, next) { |
|