Last active
August 29, 2015 14:26
-
-
Save jechav/b24ea501fc2e73139672 to your computer and use it in GitHub Desktop.
ngCordova, facebook y twitter
This file contains 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
//Facebook login | |
$scope.fbLogin = function() { | |
$cordovaOauth.facebook("1495786770635908", ["email"]).then(function(result) { | |
//alert(result.access_token); | |
$token = result.access_token; | |
$ionicLoading.show(); | |
$http.get('https://graph.facebook.com?access_token='+$token+'&ids=me').success(function(data){ | |
sendData = { | |
id: data.me.id, | |
username: data.me.first_name, | |
name: data.me.name, | |
email: data.me.email, | |
avatar: 'graph.facebook.com/v2.4/'+data.me.id+'/picture', | |
token: $token | |
} | |
//console.log(sendData); | |
FacebookAuth.login({fbUser: sendData}, function(data, status){ | |
//alert(JSON.stringify(data)); | |
if(status == 0){ | |
alert('revisa tu coneccion a internet'); | |
return false; | |
} | |
if(status == 401){ | |
alert('Hubo un problema interno'); | |
return false; | |
} | |
postLogin(data); | |
//console.log(data); | |
}); | |
}).error(function(data, status){ | |
alert(data); | |
}); | |
}, function(error, status) { | |
alert(error); | |
}); | |
} | |
$scope.twLogin = function() { | |
$cordovaOauth.twitter("erjrFqXqj5Tm1Nu4gmuiOWsau", "cODlp67NO3eRIchL8l5zpXUJBIzeXAy21G5mhwiFiLtugKOYU6").then(function(result) { | |
//first send token and userid to verify register | |
$scope.twUser = { | |
id: result.user_id, | |
token: result.oauth_token, | |
} | |
$scope.loginData.email = result.user_id + '##' + result.oauth_token; | |
$ionicLoading.show(); | |
TwitterAuth.login({twUser: $scope.twUser}, function(data){ | |
$ionicLoading.hide(); | |
if(data == 'new'){ | |
//show modal for request another info | |
$scope.showRegister(); | |
/*TwitterAuth.register(data, function(data){*/ | |
/*})*/ | |
$scope.twUser.avatar = 'https://twitter.com/'+result.screen_name+'/profile_image?size=normal'; | |
$scope.twUser.name = result.screen_name; | |
$scope.twUser.email = ''; | |
$scope.twUser.username = result.screen_name; | |
return false; | |
} | |
postLogin(data); | |
}); | |
}, function(error) { | |
alert("Error: " + error); | |
}); | |
} | |
$scope.twRegister = function(){ | |
if($scope.twUser.email == '' || $scope.twUser.email == ''){ | |
alert('Los datos ingresados no son validos'); | |
return false; | |
} | |
$ionicLoading.show(); | |
TwitterAuth.register({twUser: $scope.twUser}, function(data, status){ | |
$ionicLoading.hide(); | |
if(status == 500){ | |
if(data == 'email'){ | |
alert('La direccion de correo ya se registra en el sistema'); | |
}else if(data == 'send-email'){ | |
alert('problemas con el envio del email'); | |
} | |
return false; | |
} | |
$scope.closeRegister(); | |
//some valitations | |
postLogin(data) | |
}); | |
} | |
This file contains 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
<button class="button button-facebook ion-social-facebook" | |
ng-click="fbLogin()"> | |
<span ng-show="!loading">Ingresa </span> | |
<i ng-show="loading" class="ion-loading-b"></i> | |
</button> | |
<button class="button button-calm ion-social-twitter" | |
ng-click="twLogin()"> | |
<span ng-show="!loading">Ingresa </span> | |
<i ng-show="loading" class="ion-loading-b"></i> | |
</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment