def get(self): fb_user = None try: token = facebook.AuthenticationToken.get_authentication_token_from_code( app_id=get_facebook_id(), app_secret=get_facebook_secret(), return_url=self.request.url, ) fb_user = token.get_user() except facebook.AuthenticationError: self.session.add_flash("Oops, there appears to have been an authentication error. Please try again.") self.redirect_to('landing') #todo: save referal in cookie so that we have it at this stage. return except facebook.PermissionError: #todo: Prompt for permissions again self.session.add_flash("Looks like you didn't give us all the permissions we require. We won't be able to subscribe you.") if fb_user: existing_user = User.get_by_id(str(fb_user.id)) location = self.session.get('location') refereeID = self.session.get('refereeID') if existing_user: user = existing_user user.location = location user.put() else: email_verified = (fb_user.email != None) #emails from FB are automatically verified. user = self.createUser(fb_user, email_verified, location, refereeID) #Get these in another step of sign-up self.session['user'] = str(user.key.id()) if not self.user.email: self.redirect_to('get_email') return self.redirect_to('progress')
class GetEmail(BaseHandler): def get(self): self.render('get_email.html', action_url = self.uri_for('get_email')) def post(self): user = self.user user.email = self.request.get('email') user.email_verified = False self.welcomeEmail(user.email, str(user.key.id())) user.put() self.redirect_to('progress') config = {} config['webapp2_extras.sessions'] = { 'secret_key': str(get_facebook_secret()), } application = webapp2.WSGIApplication([ webapp2.Route('/', handler=Landing, name="landing"), webapp2.Route('/progress', handler=Progress, name="progress"), webapp2.Route('/stageone', handler=StageOne, name="stageone"), webapp2.Route('/stagetwo', handler=StageTwo, name="stagetwo"), webapp2.Route('/get_email', handler=GetEmail, name="get_email"), webapp2.Route('/referral/<refereeID>', handler=Referral, name="referral"), webapp2.Route('/wireframe', handler=WireFrame), ], debug=True, config=config )