Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. app.post('/login', async (req, res) => {
  2. let user;
  3. var captchaResponse = await fetch(`//recaptcha`
  4. , { method: "POST" })
  5. var data = await captchaResponse.json();
  6. if (!data.success) {
  7. res.status(401).send({ error: "Recaptcha Failed" })
  8. }
  9. try {
  10. var userQuery = await pool.query('SELECT * FROM users WHERE LOWER(username) = LOWER($1)', [req.body.username]);
  11. user = userQuery.rows[0];
  12. if (userQuery.rows.length == 0) {
  13. res.status(401).send({ error: "User does not exist" })
  14. } else {
  15. var correctPassword = await scrypt.verifyHash(req.body.password, user.password)
  16. if (correctPassword) {
  17. var recentTeam = await GetMostRecentTeam(user.userid);
  18. req.session.userId = user.id;
  19. if (recentTeam.rows.length == 0) {
  20. res.json({ username: user.username, userId: userId })
  21. }
  22. res.json({ username: user.username, userId: user.userId, recentteam: data.rows })
  23. }
  24. }
  25. } catch (e) {
  26. console.log(e);
  27. res.status(500).send({ error: e });
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement