| @@ 349-382 (lines=34) @@ | ||
| 346 | }); |
|
| 347 | } |
|
| 348 | ||
| 349 | bcrypt.hash(password, 10, function(err, hash) { |
|
| 350 | if (err) { |
|
| 351 | return res.status(500).json({ |
|
| 352 | errors: { |
|
| 353 | status: 500, |
|
| 354 | source: "/register", |
|
| 355 | title: "bcrypt error", |
|
| 356 | detail: "bcrypt error" |
|
| 357 | } |
|
| 358 | }); |
|
| 359 | } |
|
| 360 | ||
| 361 | db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)", |
|
| 362 | apiKey, |
|
| 363 | email, |
|
| 364 | hash, (err) => { |
|
| 365 | if (err) { |
|
| 366 | return res.status(500).json({ |
|
| 367 | errors: { |
|
| 368 | status: 500, |
|
| 369 | source: "/register", |
|
| 370 | title: "Database error", |
|
| 371 | detail: err.message |
|
| 372 | } |
|
| 373 | }); |
|
| 374 | } |
|
| 375 | ||
| 376 | return res.status(201).json({ |
|
| 377 | data: { |
|
| 378 | message: "User successfully registered." |
|
| 379 | } |
|
| 380 | }); |
|
| 381 | }); |
|
| 382 | }); |
|
| 383 | }, |
|
| 384 | ||
| 385 | checkToken: function(req, res, next) { |
|
| @@ 213-246 (lines=34) @@ | ||
| 210 | }); |
|
| 211 | } |
|
| 212 | ||
| 213 | bcrypt.hash(password, 10, function(err, hash) { |
|
| 214 | if (err) { |
|
| 215 | return res.status(500).json({ |
|
| 216 | errors: { |
|
| 217 | status: 500, |
|
| 218 | source: "/register", |
|
| 219 | title: "bcrypt error", |
|
| 220 | detail: "bcrypt error" |
|
| 221 | } |
|
| 222 | }); |
|
| 223 | } |
|
| 224 | ||
| 225 | db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)", |
|
| 226 | apiKey, |
|
| 227 | email, |
|
| 228 | hash, (err) => { |
|
| 229 | if (err) { |
|
| 230 | return res.status(500).json({ |
|
| 231 | errors: { |
|
| 232 | status: 500, |
|
| 233 | source: "/register", |
|
| 234 | title: "Database error", |
|
| 235 | detail: err.message |
|
| 236 | } |
|
| 237 | }); |
|
| 238 | } |
|
| 239 | ||
| 240 | res.status(201).json({ |
|
| 241 | data: { |
|
| 242 | message: "User successfully registered." |
|
| 243 | } |
|
| 244 | }); |
|
| 245 | }); |
|
| 246 | }); |
|
| 247 | } |
|
| 248 | ||
| 249 | function checkToken(req, res, next) { |
|