Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function registerDevice() {
- var push = new $window.Ionic.Push({
- onNotification: function() {
- $window.alert('새 댓글이 달렸습니다.');
- }
- });
- var deferred = $q.defer();
- push.register(function(data) {
- deferred.resolve(data._token);
- });
- return deferred.promise;
- }
- function login() {
- $ionicLoading.show();
- registerDevice()
- .then(function(token) {
- LoginModel.form.deviceToken = token;
- return Users.register({}, LoginModel.form).$promise;
- })
- .then(function() {
- return Users.login({}, {
- identifier: LoginModel.form.username,
- password: LoginModel.form.password
- }).$promise;
- })
- .then(function(authData) {
- appStorage.token = authData.token;
- appStorage.user = authData.user;
- $ionicLoading.hide();
- $state.go('postList');
- })
- .catch(function(err) {
- console.log(err);
- $ionicLoading.hide();
- $ionicPopup.alert({
- title: '로그인 실패',
- template: '다른 아이디로 로그인 해주세요'
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement