Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- postLoginDetails() {
- this.username = $('#login-usr').val();
- this.password = $('#login-pwd').val();
- const url = 'http://139.59.35.212/api/v1/accounts/login/';
- const body = {
- "login": this.username, // In login api, 'username/email' field is named as login, currently working for username.
- "password": this.password
- }
- const headers = new Headers(
- {
- 'Content-Type': 'application/json'
- });
- const req = this.http.post(url, body, {headers: headers})
- .subscribe(
- res => {
- console.log("POST call successful value returned in body", res);
- },
- err => {
- console.log("POST call in error", err);
- let animationName = 'animated shake';
- let animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
- //Input Fields validation and error display
- if (err.json().detail) {
- $('#login-error').text(err.json().detail);
- $('#login-error').addClass(animationName).one(animationEnd, function() {
- $(this).removeClass(animationName);
- });
- }
- if (err.json().login) {
- $('#login-usr').focus().addClass('signup-error');
- $('#login-usr').val('').attr('placeholder', err.json().login[0]);
- }
- if (err.json().password) {
- $('#login-pwd').focus().addClass('signup-error');
- $('#login-pwd').val('').attr('placeholder', err.json().password[0]);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement