Guest User

Untitled

a guest
Apr 3rd, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. app.post('/signin',(req,res) => {
  2. var loginKeyOptions = {
  3. method: 'GET',
  4. uri: 'http://124.82.79.235:58000/AuthAPI/api/auth/getloginkey',
  5. headers: {},
  6. json: true
  7. };
  8. var loginOptions = {
  9. method: 'POST',
  10. uri: 'http://124.82.79.235:58000/AuthAPI/api/auth/login',
  11. headers: {
  12. "Content-Type": "application/json",
  13. "key": ""
  14. },
  15. body: {},
  16. json: true
  17. };
  18. var roleOptions = {
  19. method: 'GET',
  20. uri: 'http://124.82.79.235:58000/UserAPI/api/Roles/my',
  21. headers: {
  22. "key": ""
  23. },
  24. json: true
  25. };
  26. var userEmail = req.body.email;
  27. var userPassword = req.body.password;
  28.  
  29. rp(loginKeyOptions)
  30. .then((loginKeyBody) => {
  31. var key = loginKeyBody.data;
  32. var payload = { username: userEmail, password: userPassword}
  33. loginOptions.headers.key = key;
  34. loginOptions.body = payload;
  35. return rp(loginOptions)
  36. })
  37. .then((loginBody) => {
  38. console.log(loginBody);
  39. res.cookie('token',loginBody.data.token);
  40. res.cookie('userId',loginBody.data.userId);
  41. roleOptions.headers.key = loginBody.data.token;
  42. return rp(roleOptions)
  43. //res.redirect('/profile');
  44. })
  45. .then((roleBody) => {
  46. console.log('roleBody');
  47. console.log(roleBody);
  48. if (roleBody.roleName === "Buyer") {
  49. res.cookie('role',roleBody.roleName);
  50. res.redirect('/profile');
  51. } else if (roleBody.roleName === "Merchant") {
  52. res.cookie('role',roleBody.roleName);
  53. res.redirect('/merchant-centre');
  54. }
  55.  
  56. })
  57. .catch((err) => {
  58. console.log(err.message);
  59. });
  60. });
Add Comment
Please, Sign In to add comment