Example #1
0
    def render_template(self, template_name, template_values):
        template_values['App'] = App
        template_values['None'] = None
        template_values['points'] = None
        template_values['username'] = ""

        user = util.get_current_user()
        if user is not None:
            template_values['username'] = user.nickname()

        user_data = UserData.get_for(user)

        template_values['user_data'] = user_data
        template_values['points'] = user_data.points if user_data else 0

        if not template_values.has_key('continue'):
            template_values['continue'] = self.request.uri

        # Always insert a post-login request before our continue url
        template_values['continue'] = util.create_post_login_url(template_values['continue'])

        template_values['login_url'] = ('%s&direct=1' % util.create_login_url(template_values['continue']))
        template_values['logout_url'] = util.create_logout_url(self.request.uri)

        template_values['is_mobile'] = self.is_mobile()

        path = os.path.join(os.path.dirname(__file__), template_name)
        self.response.out.write(template.render(path, template_values))
Example #2
0
  def get(self):
    user = users.get_current_user()
    if not user:
      self.redirect(users.create_login_url(self.request.uri))

    profile = models.Profile.all().filter('user_id =',user.user_id()).get()
    if not profile:
      self.redirect('/new_profile')
      return

    path = os.path.join(os.path.dirname(__file__), 'templates/upload_pic.html')
    addpic_html = template.render(path, {'profileid' : profile.key().id()})

    template_values = {
        'logout' : util.create_logout_url(''),
        'profile' : profile,
        'pictures' : profile.pictures,
        'inviters' : profile.inviters,
        'invitees' : profile.invitees,
        'accepters' : profile.inviters_accepted,
        'acceptees' : profile.invitees_accepted,
        'addpic_html' : addpic_html,
    }
    path = os.path.join(os.path.dirname(__file__), 'templates/home.html')
    self.response.out.write(template.render(path, template_values))
Example #3
0
  def get(self):
    self.request.path_info_pop()
    loctype = self.request.path_info_pop()
    if loctype == "place":
      locstring = self.request.path_info_pop()
    
      gc = geocode.GeoCode()
      locdata = gc.getCoords(locstring)
      try:
        coords = locdata["Placemark"][0]["Point"]["coordinates"]
      except:
        #47.6264794,-122.2051487
        coords = (-122.2051487, 47.6264794)
    
    elif loctype == "coords":
      lat = self.request.path_info_pop()
      lon = self.request.path_info_pop()
      coords = (float(lat), float(lon)) 
    elif loctype == "nearby":
      user = users.get_current_user()
      if not user:
        self.redirect(users.create_login_url(self.request.uri))

      profile = models.Profile.all().filter('user_id =',user.user_id()).get()
      if not profile:
        self.redirect('/new_profile')
        return
      coords = (profile.location.lon, profile.location.lat);
      
    else:
      self.response.out.write("""<h1>Bad loctype</h1>
        <p>Options are /place/ or /coords/</p>
      
      """)
      return
    
    template_values = {
    'logout' : util.create_logout_url(''),
    "center_lat" : coords[0],
    "center_lon" : coords[1]
    }
    path = os.path.join(os.path.dirname(__file__), 'templates/loc.html')
    self.response.out.write(template.render(path, template_values))
Example #4
0
    def render_outer(self):
        """Render the second part of the user signup step, after the user
        has verified ownership of their e-mail account.

        The request URI must include a valid token from an UnverifiedUser, and
        can be made via build_link(), or be made by a user without an existing
        password set.

        Note that the contents are actually rendered in an iframe so it
        can be sent over https (generated in render_form).
        """
        (valid_token, _) = self.resolve_token()
        user_data = UserData.current()
        if valid_token and user_data:
            if not user_data.is_phantom:
                logging.info("User tried to verify e-mail and complete a " +
                             "signup in a browser with an existing " +
                             "signed-in user. Forcefully signing old user " +
                             "out to avoid conflicts")
                self.redirect(util.create_logout_url(self.request.uri))
                return

            # Ignore phantom users.
            user_data = None

        if not valid_token and not user_data:
            # Just take them to the homepage for now.
            self.redirect("/")
            return

        transfer_token = None
        if user_data:
            if user_data.has_password():
                # The user already has a KA login - redirect them to their profile
                self.redirect(user_data.profile_root)
                return
            elif not user_data.has_sendable_email():
                # This is a case where a Facebook user logged in and tried
                # to signup for a KA password. Unfortunately, since we don't
                # have their e-mail, we can't let them proceed, since, without
                # a valid e-mail we can't reset passwords, etc.
                logging.error("User tried to signup for password with "
                              "no email associated with the account")
                self.redirect("/")
                return
            else:
                # Here we have a valid user, and need to transfer their identity
                # to the inner iframe that will be hosted on https.
                # Since their current cookies may not be transferred/valid in
                # https, mint a custom, short-lived token to transfer identity.
                transfer_token = TransferAuthToken.for_user(user_data).value

        template_values = {
            'params': util.build_params({
                                         'token': valid_token,
                                         'transfer_token': transfer_token,
                                         }),
            'continue': self.request_string("continue", default="/")
        }

        self.render_jinja2_template('completesignup.html', template_values)
Example #5
0
    def render_outer(self):
        """Render the second part of the user signup step, after the user
        has verified ownership of their e-mail account.

        The request URI must include a valid token from an UnverifiedUser, and
        can be made via build_link(), or be made by a user without an existing
        password set.

        Note that the contents are actually rendered in an iframe so it
        can be sent over https (generated in render_form).
        """
        (valid_token, _) = self.resolve_token()
        user_data = UserData.current()
        if valid_token and user_data:
            if not user_data.is_phantom:
                logging.info("User tried to verify e-mail and complete a " +
                             "signup in a browser with an existing " +
                             "signed-in user. Forcefully signing old user " +
                             "out to avoid conflicts")
                self.redirect(util.create_logout_url(self.request.uri))
                return

            # Ignore phantom users.
            user_data = None

        if not valid_token and not user_data:
            # Just take them to the homepage for now.
            self.redirect("/")
            return

        transfer_token = None
        if user_data:
            if user_data.has_password():
                # The user already has a KA login - redirect them to their profile
                self.redirect(user_data.profile_root)
                return
            elif not user_data.has_sendable_email():
                # This is a case where a Facebook user logged in and tried
                # to signup for a KA password. Unfortunately, since we don't
                # have their e-mail, we can't let them proceed, since, without
                # a valid e-mail we can't reset passwords, etc.
                logging.error("User tried to signup for password with "
                              "no email associated with the account")
                self.redirect("/")
                return
            else:
                # Here we have a valid user, and need to transfer their identity
                # to the inner iframe that will be hosted on https.
                # Since their current cookies may not be transferred/valid in
                # https, mint a custom, short-lived token to transfer identity.
                transfer_token = TransferAuthToken.for_user(user_data).value

        template_values = {
            'params':
            util.build_params({
                'token': valid_token,
                'transfer_token': transfer_token,
            }),
            'continue':
            self.request_string("continue", default="/")
        }

        self.render_jinja2_template('completesignup.html', template_values)