Ejemplo n.º 1
0
 def post(self):
   session = get_current_session()
   nickname = helper.sanitizeHtml(self.request.get('nickname'))
   email    = helper.sanitizeHtml(self.request.get('email'))
   password = helper.sanitizeHtml(self.request.get('password'))
   
   if len(nickname) > 1 and len(password) > 1 and len(email) > 1:
     password = User.slow_hash(password);
     already = User.all().filter("lowercase_nickname =",nickname.lower()).fetch(1)
     if len(already) == 0:
       user = User(nickname=nickname, lowercase_nickname=nickname.lower(),email=email,password=password, about="")
       user.put()
       helper.killmetrics("Register",nickname, "do", session, "",self)
       random_id = helper.get_session_id(session) 
       if session.is_active():
         session.terminate()
       session.regenerate_id()
       session['random_id'] = random_id
       session['user'] = user
       self.redirect('/')
     else:
       session['register_error'] = "Ya existe alguien con ese nombre de usuario <strong>" + nickname + "</strong>"
       self.redirect('/login')
   else:
     session['register_error'] = "Porfavor escribe un username y un password"
     self.redirect('/login')
Ejemplo n.º 2
0
    def post(self):
        session = get_current_session()
        nickname = helper.sanitizeHtml(self.request.get('nickname'))
        password = helper.sanitizeHtml(self.request.get('password'))

        if len(nickname) > 1 and len(password) > 1:
            password = User.slow_hash(password)
            already = User.all().filter("lowercase_nickname =",
                                        nickname.lower()).fetch(1)
            if len(already) == 0:
                user = User(nickname=nickname,
                            lowercase_nickname=nickname.lower(),
                            password=password,
                            about="")
                user.put()
                helper.killmetrics("Register", nickname, "do", session, "",
                                   self)
                random_id = helper.get_session_id(session)
                if session.is_active():
                    session.terminate()
                session.regenerate_id()
                session['random_id'] = random_id
                session['user'] = user
                self.redirect('/')
            else:
                session[
                    'register_error'] = "Ya existe alguien con ese nombre de usuario <strong>" + nickname + "</strong>"
                self.redirect('/login')
        else:
            session[
                'register_error'] = "Porfavor escribe un username y un password"
            self.redirect('/login')
  def get(self):
    session = get_current_session()
    if session.has_key('post_error'):
      post_error = session.pop('post_error')

    if session.has_key('user'):
      if hasattr(keys, 'comment_key'):
        comment_key = keys.comment_key
      user = session['user']
      #### Killmetrics test
      killmetrics_session_id = helper.get_session_id(session)
      killmetrics_key = ''
      if hasattr(keys,'base_url') and hasattr(keys,'killmetrics_dev') and helper.base_url(self) != keys.base_url:
        killmetrics_key = keys.killmetrics_dev
      if hasattr(keys,'base_url') and hasattr(keys,'killmetrics_prod') and (helper.base_url(self) == keys.base_url or helper.base_url(self) == keys.base_url_custom_url):
        killmetrics_key = keys.killmetrics_prod
      #### Killmetrics test



      get_url = helper.sanitizeHtml(self.request.get('url_bookmarklet'))
      get_title = helper.sanitizeHtml(self.request.get('title_bookmarklet'))
      self.response.out.write(template.render('templates/submit.html', locals()))
    else:
      self.redirect('/login')
Ejemplo n.º 4
0
 def get(self):
     session = get_current_session()
     helper.killmetrics("Logout", "", "do", session, "", self)
     random_id = helper.get_session_id(session)
     if session.is_active():
         session.terminate()
     session.regenerate_id()
     session["random_id"] = random_id
     self.redirect('/')
Ejemplo n.º 5
0
 def get(self):
   session = get_current_session()
   helper.killmetrics("Logout","", "do", session, "",self)
   random_id = helper.get_session_id(session) 
   if session.is_active():
     session.terminate()
   session.regenerate_id()
   session["random_id"] = random_id
   self.redirect('/')
Ejemplo n.º 6
0
  def get(self):
    page = helper.sanitizeHtml(self.request.get('pagina'))
    perPage = 20
    page = int(page) if page else 1
    realPage = page - 1
    if realPage > 0:
      prevPage = realPage
    if (page * perPage) < Post.get_cached_count():
      nextPage = page + 1

    session = get_current_session()
    on_main = True
    

    if session.has_key('user'):
      user = session['user']
    #### Killmetrics test
    killmetrics_session_id = helper.get_session_id(session)
    killmetrics_key = ''
    if hasattr(keys,'base_url') and hasattr(keys,'killmetrics_dev') and helper.base_url(self) != keys.base_url:
      killmetrics_key = keys.killmetrics_dev
    if hasattr(keys,'base_url') and hasattr(keys,'killmetrics_prod') and (helper.base_url(self) == keys.base_url or helper.base_url(self) == keys.base_url_custom_url):
      killmetrics_key = keys.killmetrics_prod
    #### Killmetrics test

    posts = Post.all().order('-karma').fetch(perPage, realPage * perPage)
    prefetch.prefetch_posts_list(posts)
    i = perPage * realPage + 1
    for post in posts:
      post.number = i
      i = i + 1
    if helper.is_json(self.request.url):
      posts_json = [p.to_json() for p in posts]
      if(self.request.get('callback')):
        self.response.headers['Content-Type'] = "application/javascript"
        self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'posts':posts_json})+');')
      else:
        self.response.headers['Content-Type'] = "application/json"
        self.response.out.write(simplejson.dumps({'posts':posts_json}))
    else:
      self.response.out.write(template.render('templates/main.html', locals()))
Ejemplo n.º 7
0
    def post(self):
        session = get_current_session()
        nickname = helper.sanitizeHtml(self.request.get("nickname"))
        password = helper.sanitizeHtml(self.request.get("password"))
        password = User.slow_hash(password)

        user = User.all().filter("lowercase_nickname =", nickname.lower()).filter("password ="******"Login", nickname, "do", session, "", self)
            random_id = helper.get_session_id(session)
            if session.is_active():
                session.terminate()
            session.regenerate_id()
            session["random_id"] = random_id
            session["user"] = user[0]
            self.redirect("/")
        else:
            session["login_error"] = "Tu usuario y/o contraseña son incorrectos"
            session["login_error_nickname"] = nickname
            self.redirect("/login")
Ejemplo n.º 8
0
  def post(self):
    session = get_current_session()
    nickname = helper.sanitizeHtml(self.request.get('nickname'))
    password = helper.sanitizeHtml(self.request.get('password'))
    password = User.slow_hash(password);

    user = User.all().filter('lowercase_nickname =',nickname.lower()).filter('password ='******'random_id'] = random_id
      session['user'] = user[0]
      self.redirect('/')
    else:
      session['login_error'] = "Usuario y password incorrectos"
      session['login_error_nickname'] = nickname
      self.redirect('/login')
Ejemplo n.º 9
0
    def post(self):
        session = get_current_session()
        nickname = helper.sanitizeHtml(self.request.get('nickname'))
        password = helper.sanitizeHtml(self.request.get('password'))
        password = User.slow_hash(password)

        user = User.all().filter('lowercase_nickname =',
                                 nickname.lower()).filter(
                                     'password ='******'random_id'] = random_id
            session['user'] = user[0]
            self.redirect('/')
        else:
            session['login_error'] = "Usuario y password incorrectos"
            session['login_error_nickname'] = nickname
            self.redirect('/login')
Ejemplo n.º 10
0
  def get(self,post_id):
    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
    #### Killmetrics test
    killmetrics_session_id = helper.get_session_id(session)
    killmetrics_key = ''
    if hasattr(keys,'base_url') and hasattr(keys,'killmetrics_dev') and helper.base_url(self) != keys.base_url:
      killmetrics_key = keys.killmetrics_dev
    if hasattr(keys,'base_url') and hasattr(keys,'killmetrics_prod') and (helper.base_url(self) == keys.base_url or helper.base_url(self) == keys.base_url_custom_url):
      killmetrics_key = keys.killmetrics_prod
    #### Killmetrics test
    if hasattr(keys, 'comment_key'):
      comment_key = keys.comment_key

    try:
      post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
      if  post  == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
        post = db.get( helper.parse_post_id( post_id ) ) 

      comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000)
      comments = helper.order_comment_list_in_memory(comments)
      prefetch.prefetch_comment_list(comments)
      display_post_title = True
      prefetch.prefetch_posts_list([post])
      if helper.is_json(post_id):
        comments_json = [c.to_json() for c in comments if not c.father_ref()] 
        if(self.request.get('callback')):
          self.response.headers['Content-Type'] = "application/javascript"
          self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'post':post.to_json(),'comments':comments_json})+')')
        else:
          self.response.headers['Content-Type'] = "application/json"
          self.response.out.write(simplejson.dumps({'post':post.to_json(),'comments':comments_json}))
      else:
        self.response.out.write(template.render('templates/post.html', locals()))
    except db.BadKeyError:
      self.redirect('/')