Last active
April 14, 2016 01:24
-
-
Save lricoy/8fd0edef0e4ed2f715946df543826b88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
login(obj) { | |
this.postRequest('http://localhost:8888/api/student_auth/login', obj).subscribe( | |
function(result) { console.log('result', result); } | |
); | |
// Não vai funcionar porque o callback acima do subscribe é assíncrono | |
// return result; | |
} | |
postRequest(url, data) { | |
this.headers = new Headers(); | |
this.headers.append('Content-Type', 'application/x-www-form-urlencoded'); | |
//this.headers.append("Content-Type", 'application/json'); | |
//this.headers.append("Authorization", 'Bearer ' + localStorage.getItem('id_token')); | |
this.requestoptions = new RequestOptions({ | |
method: RequestMethod.Post, | |
url: url, | |
headers: this.headers, | |
body: JSON.stringify(data) | |
}); | |
let getObs = this.http.request(new Request(this.requestoptions)) | |
.map((res) => { | |
return res.json() | |
}); | |
getObs.subscribe( | |
data => { | |
if(data.success) { | |
this.setTokenLocalStorage(data.token); | |
} | |
}, | |
err => { | |
return false; | |
}, | |
() => console.log('done') | |
); | |
return getObs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment