Guest User

Untitled

a guest
Jun 18th, 2018
1,288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. login(email: string, password: string) {
  2. let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
  3. let options = new RequestOptions({ headers: headers });
  4. let body = { EmailAddress: email, Password: password };
  5.  
  6. return this.http.post('http://localhost:3000/api/user/login', body, options )
  7. .map((response: Response) => {
  8. let user = response.json();
  9. if (user && user.token) {
  10. localStorage.setItem('currentUser', JSON.stringify(user));
  11. }
  12. });
  13. }
  14.  
  15. app.post('/api/user/login', urlencodedBodyparser, function (req, res) {
  16. console.log(req.body);
  17. User.find({ "EmailAddress": req.body["EmailAddress"], "Password": req.body["Password"] }, function (err, users) {
  18. console.log(users.length);
  19. if (err != null) {
  20. sendError(err, res);
  21. }
  22. if (users != null) {
  23. var count = users.length;
  24. if (count > 0) {
  25. response.data = users[0];
  26. res.json(response);
  27. }
  28. else {
  29. sendError({ message :'No user found'}, res);
  30. console.log("Login Failed");
  31. }
  32. }
  33. else {
  34. sendError(err, res);
  35. }
  36. })
  37. });
Add Comment
Please, Sign In to add comment