| @@ 232-265 (lines=34) @@ | ||
| 229 | }); |
|
| 230 | } |
|
| 231 | ||
| 232 | bcrypt.hash(password, 10, function(err, hash) { |
|
| 233 | if (err) { |
|
| 234 | return res.status(500).json({ |
|
| 235 | errors: { |
|
| 236 | status: 500, |
|
| 237 | source: "/register", |
|
| 238 | title: "bcrypt error", |
|
| 239 | detail: "bcrypt error" |
|
| 240 | } |
|
| 241 | }); |
|
| 242 | } |
|
| 243 | ||
| 244 | db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)", |
|
| 245 | apiKey, |
|
| 246 | email, |
|
| 247 | hash, (err) => { |
|
| 248 | if (err) { |
|
| 249 | return res.status(500).json({ |
|
| 250 | errors: { |
|
| 251 | status: 500, |
|
| 252 | source: "/register", |
|
| 253 | title: "Database error", |
|
| 254 | detail: err.message |
|
| 255 | } |
|
| 256 | }); |
|
| 257 | } |
|
| 258 | ||
| 259 | return res.status(201).json({ |
|
| 260 | data: { |
|
| 261 | message: "User successfully registered." |
|
| 262 | } |
|
| 263 | }); |
|
| 264 | }); |
|
| 265 | }); |
|
| 266 | }, |
|
| 267 | ||
| 268 | checkToken: function(req, res, next) { |
|
| @@ 212-245 (lines=34) @@ | ||
| 209 | }); |
|
| 210 | } |
|
| 211 | ||
| 212 | bcrypt.hash(password, 10, function(err, hash) { |
|
| 213 | if (err) { |
|
| 214 | return res.status(500).json({ |
|
| 215 | errors: { |
|
| 216 | status: 500, |
|
| 217 | source: "/register", |
|
| 218 | title: "bcrypt error", |
|
| 219 | detail: "bcrypt error" |
|
| 220 | } |
|
| 221 | }); |
|
| 222 | } |
|
| 223 | ||
| 224 | db.run("INSERT INTO users (apiKey, email, password) VALUES (?, ?, ?)", |
|
| 225 | apiKey, |
|
| 226 | email, |
|
| 227 | hash, (err) => { |
|
| 228 | if (err) { |
|
| 229 | return res.status(500).json({ |
|
| 230 | errors: { |
|
| 231 | status: 500, |
|
| 232 | source: "/register", |
|
| 233 | title: "Database error", |
|
| 234 | detail: err.message |
|
| 235 | } |
|
| 236 | }); |
|
| 237 | } |
|
| 238 | ||
| 239 | res.status(201).json({ |
|
| 240 | data: { |
|
| 241 | message: "User successfully registered." |
|
| 242 | } |
|
| 243 | }); |
|
| 244 | }); |
|
| 245 | }); |
|
| 246 | } |
|
| 247 | ||
| 248 | function checkToken(req, res, next) { |
|