Advertisement
dMe1337

ion2

Mar 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. ionViewDidLoad() {
  2. this.showLoading();
  3. this.auth.deviceExists().then(result => {
  4. if(result == 'ok') {
  5. console.log('status = ok');
  6. setTimeout(() => {
  7. this.loading.dismiss();
  8. });
  9. } else {
  10. console.log('status = error');
  11. setTimeout(() => {
  12. this.loading.dismiss();
  13. this.nav.setRoot(RegisterPage);
  14. });
  15. }
  16. }, err => {
  17. console.log('status = problem');
  18. setTimeout(() => {
  19. this.loading.dismiss();
  20. this.nav.setRoot(RegisterPage);
  21. });
  22. }).catch((err) => {
  23. this.loading.dismiss();
  24. // this.nav.setRoot(RegisterPage);
  25. this.showError(err);
  26. });
  27. }
  28.  
  29.  
  30.  
  31. deviceExists()
  32. {
  33. console.log(this.deviceID);
  34. return new Promise((resolve, reject) => {
  35. if (this.deviceID === null) {
  36. reject("Device ID is null");
  37. } else {
  38. this.isLoggedIn().subscribe(result => {
  39. resolve(result['status']);
  40. }, (err) => {
  41. reject(err);
  42. });
  43. }
  44. }).catch(err => {
  45. return "error";
  46. });
  47. }
  48.  
  49. isLoggedIn()
  50. {
  51. let url = `${this.apiURL}getdevice`;
  52. let params = `deviceid=${this.deviceID}`;
  53. let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded'});
  54. let options = new RequestOptions({ headers: headers });
  55. return this.http.post(url, params, options)
  56. .map(res => { return res.json(); })
  57. .catch(res => { return res.json(); });
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement