<s> from etc . user import create_salt_cookie <EOL> from datetime import datetime , timedelta <EOL> from django . contrib . auth import authenticate <EOL> from etc . constants import ACCOUNT_COOKIE_SALT , ACCOUNT_COOKIE <EOL> from lib . facebook import GraphAPI <EOL> import logging <EOL> from users . models import User <EOL> def attempt_login ( request , email_or_username , password ) : <EOL> auth_user = authenticate ( username = email_or_username , password = password ) <EOL> if auth_user is not None : <EOL> user = User . objects . get ( user_ptr = auth_user . id ) <EOL> login ( request , user ) <EOL> return user <EOL> return None <EOL> def login ( request , user ) : <EOL> user = user if user is not None else request . user <EOL> user . last_login = datetime . now ( ) <EOL> user . save ( ) <EOL> if user . fb_access_token : <EOL> try : <EOL> fb = GraphAPI ( user . fb_access_token ) <EOL> fb_friends = fb . request ( '<STR_LIT>' ) <EOL> user . update_fb_follows ( [ item [ '<STR_LIT:id>' ] for item in fb_friends [ '<STR_LIT:data>' ] ] ) <EOL> except Exception , err : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> if hasattr ( request , '<STR_LIT:user>' ) : <EOL> request . user = user <EOL> def logout ( request ) : <EOL> if hasattr ( request , '<STR_LIT:user>' ) : <EOL> from django . contrib . auth . models import AnonymousUser <EOL> request . user = AnonymousUser ( ) <EOL> def set_auth_cookies ( response , user ) : <EOL> response . set_cookie ( ACCOUNT_COOKIE , user . id , expires = datetime . now ( ) + timedelta ( days = <NUM_LIT> ) , path = '<STR_LIT:/>' ) <EOL> response . set_cookie ( ACCOUNT_COOKIE_SALT , create_salt_cookie ( user . id ) , expires = datetime . now ( ) + timedelta ( days = <NUM_LIT> ) , path = '<STR_LIT:/>' ) <EOL> return response <EOL> def unset_auth_cookies ( response ) : <EOL> response . delete_cookie ( ACCOUNT_COOKIE ) <EOL> response . delete_cookie ( ACCOUNT_COOKIE_SALT ) <EOL> return response </s>
