Advertisement
Guest User

Untitled

a guest
Nov 16th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. app.post("/api/loginAuth", function(req, res, next) {
  2. if(!req.body.email) {
  3. return next(JSON.stringify({"status": "error", "message": "A username must be provided"}));
  4. }
  5. if(!req.body.password) {
  6. return next(JSON.stringify({"status": "error", "message": "A password must be provided"}));
  7. }
  8. req.body.loginAuth = true;
  9. User.advancedSearch(req.body, function(error, user) {
  10. if(error) {
  11. return res.status(400).send(error);
  12. }
  13. console.log('user: ' + JSON.stringify(user));
  14. var x = [];
  15. x = user;
  16. if (x.length === 0) {
  17. return res.status(400).send('The username entered does not exist');
  18. }
  19. if(!User.validatePassword(req.body.password, user[0].password)) {
  20. return res.status(400).send("The password entered is invalid");
  21. }
  22. if (!user[0].login.emailVerified) {
  23. return res.status(400).send("The username (email) entered is not yet verified, please verify before logging in.");
  24. }
  25. User.addLoginTime(user[0].uuid, function(error, result) {
  26. if(error) {
  27. return res.status(400).send(error);
  28. }
  29. Session.create(user[0].uuid, function(error, result) {
  30. if(error) {
  31. return res.status(400).send(error);
  32. }
  33. res.send({sessionID: result.sessionID, expiry: result.expiry});
  34. });
  35. });
  36. });
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement