<s> import random <EOL> import hashlib <EOL> from django . contrib . auth . models import User <EOL> from socialite . apps . base . oauth20 . backends import BaseOauthBackend <EOL> from socialite . apps . base . oauth20 . utils import get_unique_username <EOL> from socialite . apps . facebook import helper , models <EOL> class FacebookBackend ( BaseOauthBackend ) : <EOL> def validate_service_type ( self , base_url ) : <EOL> return base_url == helper . oauth_client . oauth_base_url <EOL> def get_existing_user ( self , access_token ) : <EOL> unique_id = helper . get_unique_id ( access_token ) <EOL> try : <EOL> service = models . FacebookService . objects . get ( unique_id = unique_id ) <EOL> except models . FacebookService . DoesNotExist : <EOL> return None <EOL> return service . user <EOL> def register_user ( self , access_token ) : <EOL> try : <EOL> user_info = helper . user_info ( access_token ) <EOL> except : <EOL> return None <EOL> screen_name = '<STR_LIT>' . join ( ( user_info [ '<STR_LIT>' ] , user_info [ '<STR_LIT>' ] ) ) <EOL> user = User ( username = get_unique_username ( screen_name ) , <EOL> first_name = user_info [ '<STR_LIT>' ] , <EOL> last_name = user_info [ '<STR_LIT>' ] , <EOL> password = hashlib . md5 ( str ( random . random ( ) ) ) . hexdigest ( ) ) <EOL> user . save ( ) <EOL> return user </s>
