Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. function registerDevice() {
  2. var push = new $window.Ionic.Push({
  3. onNotification: function() {
  4. $window.alert('새 댓글이 달렸습니다.');
  5. }
  6. });
  7. var deferred = $q.defer();
  8. push.register(function(data) {
  9. deferred.resolve(data._token);
  10. });
  11. return deferred.promise;
  12. }
  13.  
  14.  
  15. function login() {
  16. $ionicLoading.show();
  17. registerDevice()
  18. .then(function(token) {
  19. LoginModel.form.deviceToken = token;
  20. return Users.register({}, LoginModel.form).$promise;
  21. })
  22. .then(function() {
  23. return Users.login({}, {
  24. identifier: LoginModel.form.username,
  25. password: LoginModel.form.password
  26. }).$promise;
  27. })
  28. .then(function(authData) {
  29. appStorage.token = authData.token;
  30. appStorage.user = authData.user;
  31. $ionicLoading.hide();
  32. $state.go('postList');
  33. })
  34. .catch(function(err) {
  35. console.log(err);
  36. $ionicLoading.hide();
  37. $ionicPopup.alert({
  38. title: '로그인 실패',
  39. template: '다른 아이디로 로그인 해주세요'
  40. });
  41. });
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement