def __init__(self): """ Initialize Facebook Graph API and check for cookies """ try: access_token = facebook.is_connected(request.cookies)["access_token"] except: raise Exception("Not authed.") self.graph = facebook.GraphAPI(access_token) self.user = self.graph.get_object("me")
def __init__(self): """ Initialize Facebook Graph API and check for cookies """ try: access_token = facebook.is_connected( request.cookies)["access_token"] except: raise Exception("Not authed.") self.graph = facebook.GraphAPI(access_token) self.user = self.graph.get_object("me")
def check(self): """ Checks if the user is authorized to view page. Needs to be admin """ if islocalhost(): return True try: Cookie = facebook.is_connected(request.cookies) if "access_token" in Cookie: graph = facebook.GraphAPI(Cookie["access_token"]) user = graph.get_object("me") if user["id"] == config.get("facebook.uid"): return True else: raise NotValidAuth("not logged in ma boi!") else: raise NotValidAuth("not logged in ma boi!") except: raise NotValidAuth("No admin cookies set")
def isadmin(): """ Checks to see if the user is the admin. If the user is on localhost or is authed by facebook as the owner of the app, then the user is admin @return True if the user is the admin @return False if the user is not the admin """ if islocalhost(): return True try: Cookie = facebook.is_connected(request.cookies) if Cookie is None: return False if "access_token" in Cookie: graph = facebook.GraphAPI(Cookie["access_token"]) user = graph.get_object("me") if user["id"] == config.get("facebook.uid"): return True except: pass return False