Example #1
0
    def current_user(self):
        if self.session.get("user") and User.get_by_key_name(self.session.get("user")['id']):
            # User is logged in
            return User.get_by_key_name(self.session.get("user")['id'])
        else:
            # Either used just logged in or just saw the first page
            # We'll see here
            cookie = facebook.get_user_from_cookie(self.request.cookies,
                                                   constants.facebook_app(self.request.host_url)['FACEBOOK_APP_ID'],
                                                   constants.facebook_app(self.request.host_url)['FACEBOOK_APP_SECRET'])
            if cookie:
                # Okay so user logged in
                # Now, check to see if existing user
                graph = facebook.GraphAPI(cookie["access_token"])
                user = User.get_by_key_name(cookie["uid"])
                new_user = False
                user_number = 0
                if not user or user.temp:
                    new_user = True
                    # Not an existing user so get user info
                    profile = graph.get_object("me")
                    user = User(key_name=str(profile["id"]),
                        id=str(profile["id"]),
                        access_level=AccessLevel.USER,
                        name=profile["name"],
                        gender=profile.get("gender"),
                        email=profile.get("email"),
                        profile_url=profile["link"],
                        access_token=cookie["access_token"],
                        location=profile['location']['name'] \
                            if 'location' in profile else None)
                    user_number = Stat.add_user(user.gender)
                elif user.access_token != cookie["access_token"]:
                    user.access_token = cookie["access_token"]

                # Update friends graph
                friends = graph.get_connections("me", "friends")['data']
                user.friends = [f['id'] for f in friends]
                #user.access_level = AccessLevel.USER
                # if Invite.get_by_key_name(user.id) or Invite.get_by_key_name(user.email):
                #   # If they're invited
                #   user.demo = True
                #   user.access_level = AccessLevel.USER
                # else:
                #   # Determine access level
                #   if new_user and user_number < constants.INVITE_LIMIT():
                #     if constants.INVITE_POLICY() == constants.InvitePolicy.NIGHTCLUB:
                #       if (user.gender == 'female' and user.has_friend()) or \
                #           (user.gender == 'male' and user.has_female_friend()):
                #         user.access_level = AccessLevel.USER
                #     if constants.INVITE_POLICY() == constants.InvitePolicy.HAS_FRIEND:
                #       if user.has_friend():
                #         user.access_level = AccessLevel.USER
                #     if constants.INVITE_POLICY() == constants.InvitePolicy.ANYBODY:
                #       user.access_level = AccessLevel.USER

                user.put()

                if new_user:
                  deferred.defer(util.update_following, user.id,
                                   _name='update-following-' + user.id + '-' + str(uuid.uuid1()))
                  # if user.access_level == AccessLevel.USER:
                  #   user.send_invite()
                  # else:
                  #   user.send_waitlist_email(user_number + 500)

                # User is now logged in
                self.session["user"] = user.to_session()
                return user
        return None
Example #2
0
    def get(self, path=None):
      if path == 'undefined' or path == 'null':
        return

      self.response.headers.add_header("Access-Control-Allow-Origin", "*")
      self.session.clear()

      mobile = self.request.host_url.startswith('http://m.') or self.request.get('mobile') \
          or 'iPhone;' in self.request.headers.get('user_agent')

      if mobile and 'onxylo' in self.request.host_url:
        self.redirect('http://www.xylocast.com')
        return



      template_data = {}
      template_data['host_url'] = self.request.host_url
      template_data['telepath'] = True
      template_data['autoplay'] = self.request.get('autoplay') == '1' if self.request.get('autoplay', None) != None else True
      if self.request.get('debug') == '3229':
        template_data['js_location'] = constants.DEBUG_JS
      elif self.request.get('prod') or not constants.DEVELOPMENT:
        template_data['js_location'] = constants.MOBILE_PROD_JS if mobile else constants.PROD_JS
      elif self.request.get('adv'):
        template_data['js_location'] = constants.ADV_JS
      else:
        template_data['js_location'] = constants.MOBILE_JS_SOURCE if mobile else constants.SIMPLE_JS

      template_data['html5'] = True
      template_data['login_required'] = constants.LOGIN_REQUIRED

      if not constants.DEVELOPMENT or self.request.get('css') or self.request.get('prod'):
        template_data['css_location'] = constants.CSS_SOURCE

      self.session['message'] = None
      # MAIL UNSUB
      if self.request.get('unsub') == '1':
        self.session['message'] = 'You are unsubscribed'

      qs = {}
      if path:
        link = Link.get_by_path(path)
        if link:
          parsed = urlparse.urlparse(link.url)
          qs = urlparse.parse_qs(parsed.query)

      # SINGLE CHANNEL
      self.session['single_channel_id'] = qs['sc'][0] if qs.get('sc') else self.request.get('sc')

      # SINGLE YOUTUBE CHANNEL
      youtube_channel_id = qs['ytc'][0] if qs.get('ytc') else self.request.get('ytc')
      #self.session['youtube_channel_id'] = youtube_channel_id
      template_data['youtube_channel_id'] = youtube_channel_id

      # LINKS
      channel_id = qs['c'][0] if qs.get('c') else self.request.get('c')
      media_id = qs['m'][0] if qs.get('m') else self.request.get('m')

      # EMBED
      template_data['embed'] = self.request.get('embed') == '1'

      self.session['channel_id'] = channel_id
      self.session['media_id'] = media_id

      template_data['power_on'] = False

      template_data['facebook_app_id'] = constants.facebook_app(self.request.host_url)['FACEBOOK_APP_ID']

      if mobile:
        path = os.path.join(os.path.dirname(__file__), 'templates/mobile.html')
        self.response.out.write(template.render(path, template_data))
      else:
        path = os.path.join(os.path.dirname(__file__), 'templates/home.html')
        self.response.out.write(template.render(path, template_data))