forked from AlmogBaku/ngAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthExample.js
77 lines (63 loc) · 2.29 KB
/
AuthExample.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* GoDisco - Social NightLife LTD Property
* Authored by Tal Gleichger
* http://www.gleichger.com/
*
* 3/12/2014 16:25
*/
app
.factory('Auth', ['$facebook', 'AuthBase', '$rootScope','$q', 'API', '$session',
function($facebook, AuthBase, $rootScope, $q,API,$session) {
var Auth = angular.extend(AuthBase, {});
Auth.setSecuredPath('/like');
/**********************************************
* Facebook implementation
*********************************************/
/**
* Request read permissions
*/
function requestReadPermissions() {
return $facebook.login();
}
Auth.login = function() {
var deferred = $q.defer();
requestReadPermissions().then(function(responseRead) {
if(responseRead.failed) {
deferred.reject({failed: responseRead.failed});
return deferred.promise;
}
deferred.resolve({"read": responseRead});
}).catch(function(error) {
deferred.reject({"read": error});
});
return deferred.promise;
};
/**
* Facebook logout
*/
Auth.logout = function() {
$facebook.logout();
};
/** Login**/
$rootScope.$on("Auth.status", function(event, status) {
if(status) {
//Server check
Auth.ready.resolve();
} else {
Auth.ready.resolve();
}
});
Auth.setIsLoggedIn(function(){
var status = $facebook.isConnected();
if(status==null) $facebook.getLoginStatus();
return status;
});
/** Facebook change status */
$rootScope.$on("fb.auth.authResponseChange", function() {
Auth.setReady($q.defer());
$rootScope.$broadcast("Auth.status", $facebook.isConnected());
});
return Auth;
}])
.run(['Auth', function(Auth) {}]);