-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.py.old
102 lines (65 loc) · 3.2 KB
/
controllers.py.old
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import graphapi
import restapi
import simplejson
from pylons import config
from pylons import request
from pylons.controllers.util import redirect_to
APIKEY = config['facebook.apikey']
APPSECRET = config['facebook.appsecret']
APPID = config['facebook.appid']
CALLBACKURL = config['facebook.callbackurl']
################################################################################
class FBPylonsController( object ) : pass
################################################################################
class RestController( FBPylonsController ) : pass
################################################################################
def get_facebook_config() : return { 'callbackurl':CALLBACKURL, 'appid':APPID, 'appsecret':APPSECRET, 'apikey':APIKEY }
def get_postauth_url() :
# if a postauth URL is given, we should redirect there
# else we should redirect to the page that needed the auth in the first place
if config.has_key('facebook.postauthurl') : return config['facebook.postauthurl']
else : return request.url
def get_auth_url(*perms) :
postauth_url = get_postauth_url()
auth_url = 'https://graph.facebook.com/oauth/authorize?client_id=%s&redirect_uri=%s' % (APPID,postauth_url)
return auth_url
class GraphController( FBPylonsController ) :
'''This is a mix-in class for Pylons controllers. Cannot be used stand-alone.'''
# def __init__( self,*args,**dargs ) :
#
# user = graphapi.get_user_from_cookie(request.cookies, APIKEY, SECRET)
# if user :
# graph = graph.GraphAPI(user["oauth_access_token"])
# profile = graph.get_object("me")
# friends = graph.get_connections("me", "friends")
#
# return super( FacebookController,self ).__init__( *args,**dargs )
def __init__( self,*args,**dargs ) :
self.user = None
self.config = get_facebook_config()
return super( GraphController,self ).__init__( *args,**dargs )
def init_user( self,*perms ) :
# print request.params
# print request.cookies
if self.user is None : # either we haven't tried 'getting' the user yet or we're somewhere in the middle of the auth sequence
# print 'user is None'
# assume we're in the middle of the auth sequence, and that the cookies will contain what we need
#self.user = graphapi.get_user_from_cookie(request.cookies, APIKEY, SECRET)
if request.params.has_key('session') : self.user = simplejson.loads(request.params['session'])
else : return self.redirect_to_auth(*perms)
# if self.user is None :
# # turns out that we were NOT in the middle of the auth sequence, so we have to initiate it
# print 'user is still None'
# return self.redirect_to_auth(*perms)
else : pass
def redirect_to_login( self ) : pass
def redirect_to_auth( self,*perms ) :
'''See http://developers.facebook.com/docs/authentication/'''
return redirect_to( get_auth_url(*perms) )
def redirect_to_perms( self ) : pass
def fbredirect( self,url ) : pass
def postauth( self,nexturl=None ) : pass
################################################################################
class FacebookController( GraphController ) : pass
class ExtendedProfileController( FacebookController ) : pass
###############################################################################