@app.before_request
def get_current_user():
 if session.get('user'):
  g.user = session.get('user')
  return
 result = get_user_from_cookie(cookies=request.cookies, app_id=FB_APP_ID, app_secret=FB_APP_SECRET)
 if result:
  user = User.query.filter((User.id == result['uid'])).first()
  if (not user):
   graph = GraphAPI(result['access_token'])
   profile = graph.get_object('me')
   if ('link' not in profile):
    profile['link'] = ''
   user = User(id=str(profile['id']), name=profile['name'], profile_url=profile['link'], access_token=result['access_token'])
   db.session.add(user)
  elif (user.access_token != result['access_token']):
   user.access_token = result['access_token']
  session['user'] = dict(name=user.name, profile_url=user.profile_url, id=user.id, access_token=user.access_token)
 db.session.commit()
 g.user = session.get('user', None)

@ app . before_request def get_current_user ( ) : if session . get ( 'user' ) : g . user = session . get ( 'user' ) return result = get_user_from_cookie ( cookies = request . cookies , app_id = FB_APP_ID , app_secret = FB_APP_SECRET ) if result : user = User . query . filter ( ( User . id == result [ 'uid' ] ) ) . first ( ) if ( not user ) : graph = GraphAPI ( result [ 'access_token' ] ) profile = graph . get_object ( 'me' ) if ( 'link' not in profile ) : profile [ 'link' ] = '' user = User ( id = str ( profile [ 'id' ] ) , name = profile [ 'name' ] , profile_url = profile [ 'link' ] , access_token = result [ 'access_token' ] ) db . session . add ( user ) elif ( user . access_token != result [ 'access_token' ] ) : user . access_token = result [ 'access_token' ] session [ 'user' ] = dict ( name = user . name , profile_url = user . profile_url , id = user . id , access_token = user . access_token ) db . session . commit ( ) g . user = session . get ( 'user' , None )
return a token_user for the owner of this process .