def actor_twitter_callback(request): logging.info("Callback URL") redirect_to = memcache.client.get('redirect_to') memcache.client.delete('redirect_to') view = user.get_user_from_cookie_or_legacy_auth(request) if view is not None: if view.extra.get('twitter_access_token') is None: twitter_user, token = util_externals.twitter_user() logging.info("Creating external profile after creates a token") ep_ref = api.create_external_profile(view.nick, 'twitter', twitter_user.screen_name, str(twitter_user.id), 'http://twitter.com/%s'%twitter_user.screen_name) view.extra['twitter_access_token'] = token view.put() if not redirect_to == 'autoclose': response = util.RedirectFlash(redirect_to, 'Oauth authentication success') return response c = template.RequestContext(request, locals()) t = loader.get_template('actor/templates/twitter_callback.html') return http.HttpResponse(t.render(c))
def twitter_user_create(request): twitter_user, token = util_externals.twitter_user() if not twitter_user: c = template.RequestContext(request, locals()) t = loader.get_template('poboxopenid/templates/twitter_login.html') return http.HttpResponse(t.render(c)) res = util_externals.reponse_if_exists(twitter_user.id, 'twitter') if res is not None: return res nick = util_externals.get_nick_from_email(twitter_user.screen_name) params = { 'nick': nick, 'password': util.generate_password(), 'first_name': twitter_user.name, 'last_name': '', 'fromopenid': True, 'email':None, } actor_ref = util_externals.user_create('twitter', params, twitter_user.screen_name, str(twitter_user.id), 'http://twitter.com/%s'%twitter_user.screen_name) logging.info("Storing twitter_access_token after create a user") actor_ref.extra['twitter_access_token'] = token actor_ref.put() response = util.RedirectFlash('/', 'Welcome to P.O.BoxPress') user.set_user_cookie(response, actor_ref) return response #@decorator_from_middleware(FacebookMiddleware) #@facebook.require_login('/facebook/signin', False) #def facebook_processuser(request): # c = template.RequestContext(request, locals()) # t = loader.get_template('poboxopenid/templates/facebook_login.html') # return http.HttpResponse(t.render(c)) #@decorator_from_middleware(FacebookMiddleware) #@facebook.require_login('/facebook/signin', False) #def facebook_canvas(request): # values = request.facebook.users.getInfo([request.facebook.uid], ['first_name', 'is_app_user', 'has_added_app'])[0] # # name, is_app_user, has_added_app = values['first_name'], values['is_app_user'], values['has_added_app'] # # if has_added_app == '0': # return request.facebook.redirect(request.facebook.get_add_url()) # # c = template.RequestContext(request, locals()) # t = loader.get_template('poboxopenid/templates/canvas.fbml') # return http.HttpResponse(t.render(c))