directives directive fbLogin function return templateUrl loginpanel ht

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
directives.directive("fbLogin", [function(){
return {
templateUrl : "loginpanel.html",
replace:true,
scope:{
fbloginurl: "="
},
controller: function($scope, $log, $facebook, $http, $cookies, AuthService){
$log.debug("Fb login Url = " + $scope.fbloginurl);
$scope.showFBUser = false; //if this is set, FB user info will be shown
$scope.showFBLoginButton = false;
//check if user is logged in
$facebook.getLoginStatus().then(function(response, b, c){
debugger;
if(response.status == "connected"){ //
$facebook.api("/me?fields=name,picture").then(function(response){
$log.debug("exe FB me function");
AuthService.setUser(response);
$scope.user = AuthService.currentUser();
$scope.showFBUser = true;
$log.debug("exe FB me function -out");
});
}else if(response.status == "unknown" || response.status=="not_authorized"){
$scope.showFBLoginButton = true;
}
}, function(response){//error
$log.error("Issue in trying to get FB login status");
$log.error(response);
});
//fucntion to logout the user from facebook
$scope.fbLogout = function(){
$facebook.login().then(function(){
$log.debug("user logged out of FB");
$scope.showFBLoginButton = true;
$scope.showFBUser = false;
});
};