<s> import time <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from facebook . auth import app_authentication <EOL> from facebook . extras . django . facebook . models import FacebookProfile <EOL> from facebook . graph import Graph <EOL> class FacebookAuthBackend ( object ) : <EOL> supports_anonymous_user = False <EOL> def authenticate ( self , token = None , request = None ) : <EOL> access_token = app_authentication ( <EOL> token , <EOL> settings . FACEBOOK_APP_SETTINGS [ "<STR_LIT>" ] , <EOL> settings . FACEBOOK_APP_SETTINGS [ "<STR_LIT>" ] , <EOL> settings . FACEBOOK_APP_SETTINGS [ "<STR_LIT>" ] <EOL> ) <EOL> profile = Graph ( access_token ) . get_user ( ) <EOL> try : <EOL> fb_profile = FacebookProfile . objects . get ( <EOL> facebook_id = str ( profile [ "<STR_LIT:id>" ] ) <EOL> ) <EOL> fb_profile . access_token = access_token <EOL> fb_profile . save ( ) <EOL> user = fb_profile . user <EOL> except FacebookProfile . DoesNotExist : <EOL> user = User . objects . create ( <EOL> username = profile [ "<STR_LIT:id>" ] , <EOL> email = profile [ "<STR_LIT:email>" ] , <EOL> first_name = profile [ "<STR_LIT>" ] , <EOL> last_name = profile [ "<STR_LIT>" ] <EOL> ) <EOL> formatted_dob = time . strftime ( <EOL> "<STR_LIT>" , <EOL> time . strptime ( profile [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> ) <EOL> fb_profile = FacebookProfile . objects . create ( <EOL> user = user , <EOL> facebook_id = profile [ "<STR_LIT:id>" ] , <EOL> access_token = access_token , <EOL> dob = formatted_dob <EOL> ) <EOL> return user <EOL> def get_user ( self , user_id ) : <EOL> try : <EOL> return User . objects . get ( pk = user_id ) <EOL> except User . DoesNotExist : <EOL> return None </s>
