Advertisement
Guest User

Untitled

a guest
Mar 7th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. postLoginDetails() {
  2. this.username = $('#login-usr').val();
  3. this.password = $('#login-pwd').val();
  4.  
  5. const url = 'http://139.59.35.212/api/v1/accounts/login/';
  6.  
  7. const body = {
  8. "login": this.username, // In login api, 'username/email' field is named as login, currently working for username.
  9. "password": this.password
  10. }
  11. const headers = new Headers(
  12. {
  13. 'Content-Type': 'application/json'
  14. });
  15.  
  16. const req = this.http.post(url, body, {headers: headers})
  17. .subscribe(
  18. res => {
  19. console.log("POST call successful value returned in body", res);
  20. },
  21. err => {
  22. console.log("POST call in error", err);
  23. let animationName = 'animated shake';
  24. let animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
  25. //Input Fields validation and error display
  26. if (err.json().detail) {
  27. $('#login-error').text(err.json().detail);
  28. $('#login-error').addClass(animationName).one(animationEnd, function() {
  29. $(this).removeClass(animationName);
  30. });
  31. }
  32. if (err.json().login) {
  33. $('#login-usr').focus().addClass('signup-error');
  34. $('#login-usr').val('').attr('placeholder', err.json().login[0]);
  35. }
  36. if (err.json().password) {
  37. $('#login-pwd').focus().addClass('signup-error');
  38. $('#login-pwd').val('').attr('placeholder', err.json().password[0]);
  39. }
  40. });
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement