#NEWLINE# def login( request ) : #NEWLINE# #INDENT# token = None #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# token = request . POST . get ( 'token' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# token = request . GET . get ( 'token' ) #NEWLINE# #UNINDENT# if ( token == None ) : #NEWLINE# #INDENT# return redirect ( '/demo.html?loginFailed=true' ) #NEWLINE# #UNINDENT# u = None #NEWLINE# try : #NEWLINE# #INDENT# u = urlopen ( ( 'https://rpxnow.com/api/v2/auth_info?apiKey=%s&token=%s' % ( JANRAIN_API_KEY , token ) ) ) #NEWLINE# auth_info = json . loads ( u . read ( ) ) #NEWLINE# status = auth_info [ 'stat' ] #NEWLINE# if ( status != 'ok' ) : #NEWLINE# #INDENT# return redirect ( '/demo.html?loginFailed=true' ) #NEWLINE# #UNINDENT# profile = auth_info [ 'profile' ] #NEWLINE# identifier = profile [ 'identifier' ] #NEWLINE# email = ( profile [ 'email' ] if profile . has_key ( 'email' ) else None ) #NEWLINE# candidate = User . objects . filter ( open_id = identifier ) #NEWLINE# user = None #NEWLINE# portfolio = None #NEWLINE# target = 'transactions' #NEWLINE# if ( candidate . count ( ) == 0 ) : #NEWLINE# #INDENT# user = create_user ( identifier , email ) #NEWLINE# portfolio = create_portfolio ( user , 'Default' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# user = candidate [ 0 ] #NEWLINE# portfolio = Portfolio . objects . filter ( user__id__exact = user . id ) [ 0 ] #NEWLINE# target = 'positions' #NEWLINE# #UNINDENT# request . session [ 'user_id' ] = user . id #NEWLINE# return redirect_to_portfolio_action ( target , portfolio ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if ( u != None ) : #NEWLINE# #INDENT# u . close ( )