def save( self ): try: realID = RealID.objects.get( user__exact = self.user, account = self.cleaned_data['account'] ) realID.name = self.cleaned_data['realID'] except RealID.DoesNotExist: realID = RealID( user = self.user, name = self.cleaned_data['realID'], account = self.cleaned_data['account'] ) realID.save()
def callback( request ): try: requestKey = request.GET['oauth_token'] verifier = request.GET['oauth_verifier'] except Exception: # TODO error page raise try: requestToken = Request.objects.get( user__exact = request.user ) except Request.DoesNotExist: # TODO error page raise api = PlurkAPI( plurk.CONSUMER_KEY, plurk.CONSUMER_SECRET ) api._oauth.oauth_token['oauth_token'] = requestToken.key api._oauth.oauth_token['oauth_token_secret'] = requestToken.secret requestToken.delete() try: api._oauth.get_access_token( verifier ) accessKey = api._oauth.oauth_token['oauth_token'] accessSecret = api._oauth.oauth_token['oauth_token_secret'] except Exception: # TODO error page raise try: record = Access.objects.get( user__exact = request.user ) record.key = accessKey record.secret = accessSecret except Access.DoesNotExist: record = Access( user = request.user, key = accessKey, secret = accessSecret ) record.save() # add read id for user me = api.callAPI( '/APP/Profile/getOwnProfile' ) if me == None: raise Exception( api.error() ) me = me['user_info']['nick_name'] try: realID = RealID.objects.get( user__exact = request.user, account__exact = me ) realID.name = request.user.username except RealID.DoesNotExist: realID = RealID( user = request.user, name = request.user.username, account = me ) realID.save() return redirect( '/' )