コード例 #1
0
ファイル: main.py プロジェクト: osiux/Noticias-HAcker
 def post(self, code):
     session = get_current_session()
     code = helper.parse_post_id(
         helper.sanitizeHtml(self.request.get('code')))
     password = helper.sanitizeHtml(self.request.get('password'))
     password_confirm = helper.sanitizeHtml(
         self.request.get('password_confirm'))
     if password != password_confirm:
         session['error'] = "Ocurrió un error al confirmar el password"
         self.redirect('/recovery/' + code)
         return
     ticket = Ticket.all().filter('code', code).filter('is_active',
                                                       True).fetch(1)
     if len(ticket) == 1:
         ticket = ticket[0]
         user = ticket.user
         user.password = User.slow_hash(password)
         user.put()
         ticket.is_active = False
         ticket.put()
         session[
             'success'] = "Se ha cambiado el password correctamente, ya puedes iniciar sesión con tus nuevas credenciales"
         self.redirect('/login')
     else:
         self.redirect('/')
コード例 #2
0
  def post(self, post_id):
    session = get_current_session()
    title = helper.sanitizeHtml(self.request.get('title'))
    message = helper.sanitizeHtml(self.request.get('message'))

    if session.has_key('user'):
      user = session['user']
      try:
        post = db.get(helper.parse_post_id(post_id))
        if post.can_edit():
          if len(title) > 0:
            post.title = title
          if post.message is not None and message is not None:
            post.message = message
          post.edited = True
          post.put()
	  
	  #index with indextank
	  helper.indextank_document(helper.base_url(self), post)

	  self.redirect('/noticia/' + str(post.key()))
        else:
          self.redirect('/')
      except db.BadKeyError:
        self.redirect('/')  
    else:
      self.redirect('/')
コード例 #3
0
    def post(self, post_id):
        session = get_current_session()
        title = helper.sanitizeHtml(self.request.get('title'))
        message = helper.sanitizeHtml(self.request.get('message'))

        if session.has_key('user'):
            user = session['user']
            try:
                post = db.get(helper.parse_post_id(post_id))
                if post.can_edit():
                    if len(title) > 0:
                        post.title = title
                    if post.message is not None and message is not None:
                        post.message = message
                    post.edited = True
                    post.put()

                    #index with indextank
                    helper.indextank_document(helper.base_url(self), post)

                    self.redirect('/noticia/' + str(post.key()))
                else:
                    self.redirect('/')
            except db.BadKeyError:
                self.redirect('/')
        else:
            self.redirect('/')
コード例 #4
0
  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')
コード例 #5
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')
コード例 #6
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
  def get(self, user):
    page = helper.sanitizeHtml(self.request.get('pagina'))
    target_user_str= helper.sanitizeHtml(helper.parse_post_id(user))
    perPage = 20
    page = int(page) if page else 1
    realPage = page - 1
    if realPage > 0:
      prevPage = realPage

    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
    target_user = User.all().filter('lowercase_nickname =', target_user_str).fetch(1)
    if len(target_user) > 0:
      posts = Post.all().filter('user ='******'-created').fetch(perPage,perPage * realPage)
      if (page * perPage) < Post.all().filter('user ='******'-created').count():
        nextPage = page + 1
      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()))
    else:
      self.redirect('/')
コード例 #7
0
  def get(self, user):
    page = helper.sanitizeHtml(self.request.get('pagina'))
    target_user_str= helper.sanitizeHtml(helper.parse_post_id(user))
    perPage = 20
    page = int(page) if page else 1
    realPage = page - 1
    if realPage > 0:
      prevPage = realPage

    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
    target_user = User.all().filter('lowercase_nickname =', target_user_str).fetch(1)
    if len(target_user) > 0:
      posts = Post.all().filter('user ='******'-created').fetch(perPage,perPage * realPage)
      if (page * perPage) < Post.all().filter('user ='******'-created').count():
        nextPage = page + 1
      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()))
    else:
      self.redirect('/')
コード例 #8
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')
コード例 #9
0
    def post(self):
        session = get_current_session()
        url = self.request.get("url")
        title = helper.sanitizeHtml(self.request.get("title"))
        message = helper.sanitizeHtml(self.request.get("message"))
        nice_url = helper.sluglify(title)

        if session.has_key("user"):
            if len(nice_url) > 0:
                user = session["user"]
                if len(message) == 0:  # is it a post or a message?
                    # Check that we don't have the same URL within the last 'check_days'
                    since_date = date.today() - timedelta(days=7)
                    q = Post.all().filter("created >", since_date).filter("url =", url).count()
                    url_exists = q > 0
                    q = Post.all().filter("nice_url", nice_url).count()
                    nice_url_exist = q > 0
                    try:
                        if not url_exists:
                            if not nice_url_exist:
                                post = Post(url=url, title=title, message=message, user=user, nice_url=nice_url)
                                post.put()
                                vote = Vote(user=user, post=post, target_user=post.user)
                                vote.put()
                                Post.remove_cached_count_from_memcache()
                                self.redirect("/noticia/" + str(post.nice_url))
                            else:
                                session["post_error"] = "Este titulo ha sido usado en una noticia anterior"
                                self.redirect("/agregar")
                        else:
                            session["post_error"] = "Este link ha sido entregado en los ultimo 7 dias"
                            self.redirect("/agregar")
                    except db.BadValueError:
                        session["post_error"] = "El formato del link no es valido"
                        self.redirect("/agregar")
                else:
                    q = Post.all().filter("nice_url", nice_url).count()
                    nice_url_exist = q > 0
                    if not nice_url_exist:
                        post = Post(title=title, message=message, user=user, nice_url=nice_url)
                        post.put()
                        post.url = helper.base_url(self) + "/noticia/" + post.nice_url
                        post.put()
                        Post.remove_cached_count_from_memcache()
                        vote = Vote(user=user, post=post, target_user=post.user)
                        vote.put()
                        self.redirect("/noticia/" + post.nice_url)
                    else:
                        session["post_error"] = "Este titulo ha sido usado en una noticia anterior"
                        self.redirect("/agregar")
            else:
                session["post_error"] = "Necesitas agregar un titulo"
                self.redirect("/agregar")
        else:
            self.redirect("/login")
コード例 #10
0
    def get(self):
        session = get_current_session()
        if session.has_key("post_error"):
            post_error = session.pop("post_error")

        if session.has_key("user"):
            user = session["user"]
            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")
コード例 #11
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
  def get(self):
    session = get_current_session()
    if session.has_key('post_error'):
      post_error = session.pop('post_error')

    if session.has_key('user'):
      user = session['user']
      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')
コード例 #12
0
ファイル: main.py プロジェクト: mauropm/Noticias-HAcker
    def post(self):
        session = get_current_session()
        url = self.request.get('url')
        title = helper.sanitizeHtml(self.request.get('title'))
        message = helper.sanitizeHtml(self.request.get('message'))

        if session.has_key('user'):
            if len(title) > 0:
                user = session['user']
                if len(message) == 0:  #is it a post or a message?
                    #Check that we don't have the same URL within the last 'check_days'
                    since_date = date.today() - timedelta(days=7)
                    q = Post.all().filter("created >",
                                          since_date).filter("url =",
                                                             url).count()
                    url_exists = q > 0
                    try:
                        if not url_exists:
                            post = Post(url=url,
                                        title=title,
                                        message=message,
                                        user=user)
                            post.put()
                            vote = Vote(user=user,
                                        post=post,
                                        target_user=post.user)
                            vote.put()
                            Post.remove_cached_count_from_memcache()
                            self.redirect('/noticia/' + str(post.key()))
                        else:
                            session[
                                'post_error'] = "Este link ha sido entregado en los ultimo 7 dias"
                            self.redirect('/agregar')
                    except db.BadValueError:
                        session[
                            'post_error'] = "El formato del link no es valido"
                        self.redirect('/agregar')
                else:
                    post = Post(title=title, message=message, user=user)
                    post.put()
                    post.url = helper.base_url(self) + "/noticia/" + str(
                        post.key())
                    post.put()
                    Post.remove_cached_count_from_memcache()
                    vote = Vote(user=user, post=post, target_user=post.user)
                    vote.put()
                    self.redirect('/noticia/' + str(post.key()))
            else:
                session['post_error'] = "Necesitas agregar un titulo"
                self.redirect('/agregar')
        else:
            self.redirect('/login')
コード例 #13
0
    def get(self):
        session = get_current_session()
        if session.has_key('post_error'):
            post_error = session.pop('post_error')

        if session.has_key('user'):
            user = session['user']
            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')
コード例 #14
0
ファイル: main.py プロジェクト: osiux/Noticias-HAcker
    def get(self):
        session = get_current_session()
        if session.has_key('user'):
            user = session['user']
            page = helper.sanitizeHtml(self.request.get('pagina'))
            perPage = 10
            page = int(page) if page else 1
            realPage = page - 1
            inboxAll = True
            if realPage > 0:
                prevPage = realPage
            if (page * perPage) < Notification.all().filter(
                    "target_user ="******"target_user ="******"-created").fetch(perPage, perPage * realPage)
            prefetch.prefetch_refprops(notifications, Notification.post,
                                       Notification.comment,
                                       Notification.sender_user)
            self.response.out.write(
                template.render('templates/notifications.html', locals()))
        else:
            self.redirect('/login')
コード例 #15
0
  def post(self, post_id):
    session = get_current_session()
    if session.has_key('user'):
      message = helper.sanitizeHtml(self.request.get('message'))
      user = session['user']
      key = self.request.get('comment_key')
      if len(message) > 0 and 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 ) ) 

          post.remove_from_memcache()
          comment = Comment(message=message,user=user,post=post)
          comment.put()
          helper.killmetrics("Comment","Root", "posted", session, "",self)
          vote = Vote(user=user, comment=comment, target_user=user)
          vote.put()
          Notification.create_notification_for_comment_and_user(comment,post.user)
          self.redirect('/noticia/' + post_id)
        except db.BadKeyError:
          self.redirect('/')
      else:
        self.redirect('/noticia/' + post_id)
    else:
      self.redirect('/login')
コード例 #16
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
  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()
    if session.has_key('user'):
      user = session['user']
    posts = Post.all().order('-created').fetch(perPage,perPage * realPage)
    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()))
コード例 #17
0
ファイル: main.py プロジェクト: osiux/Noticias-HAcker
    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()
        if session.has_key('user'):
            user = session['user']
        posts = Post.all().order('-created').fetch(perPage, perPage * realPage)
        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()))
コード例 #18
0
ファイル: main.py プロジェクト: osiux/Noticias-HAcker
    def get(self, nickname):
        page = helper.sanitizeHtml(self.request.get('pagina'))
        perPage = 6
        page = int(page) if page else 1
        realPage = page - 1
        if realPage > 0:
            prevPage = realPage
        # this is used to tell the template to include the topic
        threads = True

        session = get_current_session()
        if session.has_key('user'):
            user = session['user']
        thread_user = User.all().filter('lowercase_nickname =',
                                        nickname.lower()).fetch(1)
        if len(thread_user) > 0:
            thread_user = thread_user[0]
            user_comments = Comment.all().filter(
                'user ='******'-created').fetch(perPage,
                                                     realPage * perPage)
            comments = helper.filter_user_comments(user_comments, thread_user)
            if (page * perPage) < Comment.all().filter('user ='******'templates/threads.html', locals()))
        else:
            self.redirect('/')
コード例 #19
0
 def post(self):
   session = get_current_session()
   email = helper.sanitizeHtml(self.request.get('email'))
   if len(email) > 1:      
     users = User.all().filter("email =", email).fetch(1)
     if len(users) == 1:
       if session.is_active():
         session.terminate()
       user = users[0]
       Ticket.deactivate_others(user)
       ticket = Ticket(user=user,code=Ticket.create_code(user.password + user.nickname + str(random.random())))
       ticket.put()
       code = ticket.code
       host = self.request.url.replace(self.request.path,'',1)
     
       sender = "Santiago Zavala - Fogata.co <*****@*****.**>"
       logging.info("sender = " + sender ) 
       mail.send_mail(sender=sender,
         to=user.nickname + "<"+user.email+">",
         subject="Liga para restablecer password",
         html=template.render('templates/mail/forgotten-password-email.html', locals()),
         body=template.render('templates/mail/forgotten-password-email-plain.html', locals()))
     
       session['forgotten_password_ok'] = "Se ha enviado un correo electrónico a tu bandeja de entrada con las instrucciones"
     else:
       session['forgotten_password_error'] = "El correo electronico <strong>"+ email +"</strong> no existe en nuestra base de datos"
   else:
     session['forgotten_password_error'] = "Debes especificar tu correo electrónico"
    
   self.redirect('/olvide-el-password')
コード例 #20
0
ファイル: main.py プロジェクト: osiux/Noticias-HAcker
 def post(self, comment_id):
     session = get_current_session()
     if session.has_key('user'):
         message = helper.sanitizeHtml(self.request.get('message'))
         user = session['user']
         if len(message) > 0:
             try:
                 parentComment = db.get(comment_id)
                 comment = Comment(message=message,
                                   user=user,
                                   post=parentComment.post,
                                   father=parentComment)
                 comment.put()
                 comment.post.remove_from_memcache()
                 vote = Vote(user=user, comment=comment, target_user=user)
                 vote.put()
                 Notification.create_notification_for_comment_and_user(
                     comment, parentComment.user)
                 self.redirect('/noticia/' + str(parentComment.post.key()))
             except db.BadKeyError:
                 self.redirect('/')
         else:
             self.redirect('/responder/' + comment_id)
     else:
         self.redirect('/login')
コード例 #21
0
ファイル: main.py プロジェクト: osiux/Noticias-HAcker
    def post(self, post_id):
        session = get_current_session()
        if session.has_key('user'):
            message = helper.sanitizeHtml(self.request.get('message'))
            user = session['user']
            if len(message) > 0:
                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))

                    post.remove_from_memcache()
                    comment = Comment(message=message, user=user, post=post)
                    comment.put()
                    vote = Vote(user=user, comment=comment, target_user=user)
                    vote.put()
                    Notification.create_notification_for_comment_and_user(
                        comment, post.user)
                    self.redirect('/noticia/' + post_id)
                except db.BadKeyError:
                    self.redirect('/')
            else:
                self.redirect('/noticia/' + post_id)
        else:
            self.redirect('/login')
コード例 #22
0
 def post(self):
   session = get_current_session()
   email = helper.sanitizeHtml(self.request.get('email'))
   if len(email) > 1:      
     users = User.all().filter("email =", email).fetch(1)
     if len(users) == 1:
       if session.is_active():
         session.terminate()
       user = users[0]
       Ticket.deactivate_others(user)
       ticket = Ticket(user=user,code=Ticket.create_code(user.password + user.nickname + str(random.random())))
       ticket.put()
       code = ticket.code
       host = self.request.url.replace(self.request.path,'',1)
      
       mail.send_mail(sender="NoticiasHacker <*****@*****.**>",
         to=user.nickname + "<"+user.email+">",
         subject="Liga para restablecer password",
         html=template.render('templates/mail/forgotten-password-email.html', locals()),
         body=template.render('templates/mail/forgotten-password-email-plain.html', locals()))
     
       session['forgotten_password_ok'] = "Se ha enviado un correo electrónico a tu bandeja de entrada con las instrucciones"
     else:
       session['forgotten_password_error'] = "El correo electronico <strong>"+ email +"</strong> no existe en nuestra base de datos"
   else:
     session['forgotten_password_error'] = "Debes especificar tu correo electrónico"
    
   self.redirect('/olvide-el-password')
コード例 #23
0
ファイル: LoginHandler.py プロジェクト: zetta/Noticias-HAcker
  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 ='******'user'] = user[0]
      self.redirect('/')
    else:
      session['login_error'] = "Usuario y password incorrectos"
      session['login_error_nickname'] = nickname
      self.redirect('/login')
コード例 #24
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
  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 ='******'user'] = user[0]
      self.redirect('/')
    else:
      session['login_error'] = "Usuario y password incorrectos"
      session['login_error_nickname'] = nickname
      self.redirect('/login')
コード例 #25
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
  def post(self):
    session = get_current_session()
    url = self.request.get('url')
    title = helper.sanitizeHtml(self.request.get('title'))
    message = helper.sanitizeHtml(self.request.get('message'))

    if session.has_key('user'):
      if len(title) > 0:
        user = session['user']
        if len(message) == 0: #is it a post or a message?
          #Check that we don't have the same URL within the last 'check_days'
          since_date = date.today() - timedelta(days=7)
          q = Post.all().filter("created >", since_date).filter("url =", url).count()
          url_exists = q > 0
          try:
            if not url_exists:
              post = Post(url=url,title=title,message=message, user=user)
              post.put()
              vote = Vote(user=user, post=post, target_user=post.user)
              vote.put()
              Post.remove_cached_count_from_memcache()
              self.redirect('/noticia/' + str(post.key()));
            else:
              session['post_error'] = "Este link ha sido entregado en los ultimo 7 dias"
              self.redirect('/agregar')
          except db.BadValueError:
            session['post_error'] = "El formato del link no es valido"
            self.redirect('/agregar')
        else:
          post = Post(title=title,message=message, user=user)
          post.put()
          post.url = helper.base_url(self) + "/noticia/" + str(post.key())
          post.put()
          Post.remove_cached_count_from_memcache()
          vote = Vote(user=user, post=post, target_user=post.user)
          vote.put()
          self.redirect('/noticia/' + str(post.key()));
      else:
        session['post_error'] = "Necesitas agregar un titulo"
        self.redirect('/agregar')
    else:
      self.redirect('/login')
コード例 #26
0
 def post(self,code):
   session = get_current_session()
   code = helper.parse_post_id(helper.sanitizeHtml(self.request.get('code')))
   password = helper.sanitizeHtml(self.request.get('password'))
   password_confirm = helper.sanitizeHtml(self.request.get('password_confirm'))
   if password != password_confirm :
     session['error'] = "Ocurrió un error al confirmar el password"
     self.redirect('/recovery/'+code)
     return
   ticket = Ticket.all().filter('code',code).filter('is_active',True).fetch(1)
   if len(ticket) == 1:
     ticket = ticket[0]
     user = ticket.user
     user.password = User.slow_hash(password)
     user.put()
     ticket.is_active = False
     ticket.put()
     session['success'] = "Se ha cambiado el password correctamente, ya puedes iniciar sesión con tus nuevas credenciales"
     self.redirect('/login')
   else:
     self.redirect('/')
コード例 #27
0
ファイル: LoginHandler.py プロジェクト: cesarsalazar/Fogata
    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")
コード例 #28
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
 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()
       if session.is_active():
         session.terminate()
       session.regenerate_id()
       session['user'] = user
       self.redirect('/')
     else:
       session['register_error'] = "Ya existe alguien con ese nombre de usuario " + nickname
       self.redirect('/login')
   else:
     session['register_error'] = "Porfavor escribe un username y un password"
     self.redirect('/login')
コード例 #29
0
ファイル: main.py プロジェクト: osiux/Noticias-HAcker
 def get(self, notification_key):
     session = get_current_session()
     if session.has_key('user'):
         user = session['user']
         try:
             notification = db.get(helper.sanitizeHtml(notification_key))
             if str(notification.target_user.key()) == str(user.key()):
                 notification.read = True
                 notification.put()
                 user.remove_notifications_from_memcache()
                 self.response.out.write('Ok')
             else:
                 self.response.out.write('Bad')
         except db.BadKeyError:
             self.response.out.write('Bad')
     else:
         self.response.out.write('Bad')
コード例 #30
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
 def get(self,notification_key):
   session = get_current_session()
   if session.has_key('user'):
     user = session['user']
     try:
       notification = db.get(helper.sanitizeHtml(notification_key))
       if str(notification.target_user.key()) == str(user.key()):
         notification.read = True
         notification.put()
         user.remove_notifications_from_memcache()
         self.response.out.write('Ok')
       else:
         self.response.out.write('Bad')
     except db.BadKeyError:
       self.response.out.write('Bad')
   else:
     self.response.out.write('Bad')
コード例 #31
0
  def get(self):
    session = get_current_session()

    if session.has_key('user'):
      user = session['user']
    else:
      session['login_error'] = "Inicia sesión para agregar una noticia"
      self.redirect('/login')

    if session.has_key('post_error'):
      post_error = session.pop('post_error')

    get_url = self.request.get('url')
    get_title = helper.sanitizeHtml(self.request.get('title'))
    nice_url = helper.sluglify(get_title)
    comment_key = keys.comment_key
 
    self.response.out.write(template.render('templates/submit.html', locals()))
コード例 #32
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
  def get(self):
    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
      page = helper.sanitizeHtml(self.request.get('pagina'))
      perPage = 10
      page = int(page) if page else 1
      realPage = page - 1
      inboxAll = True
      if realPage > 0:
        prevPage = realPage
      if (page * perPage) < Notification.all().filter("target_user ="******"target_user ="******"-created").fetch(perPage,perPage * realPage)
      prefetch.prefetch_refprops(notifications,Notification.post,Notification.comment,Notification.sender_user)
      self.response.out.write(template.render('templates/notifications.html', locals()))
    else:
      self.redirect('/login')
コード例 #33
0
  def post(self, comment_id):
    session = get_current_session()
    message = helper.sanitizeHtml(self.request.get('message'))

    if session.has_key('user'):
      user = session['user']
      try:
        comment = db.get(helper.parse_post_id(comment_id))
        if comment.can_edit():
          if message is not None:
            comment.message = message
          comment.edited = True
          comment.put()
          self.redirect('/noticia/' + str(comment.post.key()))
        else:
          self.redirect('/')
      except db.BadKeyError:
        self.redirect('/')  
    else:
      self.redirect('/')
コード例 #34
0
ファイル: main.py プロジェクト: osiux/Noticias-HAcker
    def post(self, comment_id):
        session = get_current_session()
        message = helper.sanitizeHtml(self.request.get('message'))

        if session.has_key('user'):
            user = session['user']
            try:
                comment = db.get(helper.parse_post_id(comment_id))
                if comment.can_edit():
                    if message is not None:
                        comment.message = message
                    comment.edited = True
                    comment.put()
                    self.redirect('/noticia/' + str(comment.post.key()))
                else:
                    self.redirect('/')
            except db.BadKeyError:
                self.redirect('/')
        else:
            self.redirect('/')
コード例 #35
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()))
コード例 #36
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
 def post(self,comment_id):
   session = get_current_session()
   if session.has_key('user'):
     message = helper.sanitizeHtml(self.request.get('message'))
     user = session['user']
     if len(message) > 0:
       try:
         parentComment = db.get(comment_id)
         comment = Comment(message=message,user=user,post=parentComment.post, father=parentComment)
         comment.put()
         comment.post.remove_from_memcache()
         vote = Vote(user=user, comment=comment, target_user=user)
         vote.put()
         Notification.create_notification_for_comment_and_user(comment,parentComment.user)
         self.redirect('/noticia/' + str(parentComment.post.key()))
       except db.BadKeyError:
         self.redirect('/')
     else:
       self.redirect('/responder/' + comment_id)
   else:
     self.redirect('/login')
コード例 #37
0
ファイル: main.py プロジェクト: mantus/Noticias-HAcker
  def get(self,nickname):
    page = helper.sanitizeHtml(self.request.get('pagina'))
    perPage = 6
    page = int(page) if page else 1
    realPage = page - 1
    if realPage > 0:
      prevPage = realPage
    # this is used to tell the template to include the topic
    threads = True

    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
    thread_user = User.all().filter('lowercase_nickname =',nickname.lower()).fetch(1)
    if len(thread_user) > 0:
      thread_user = thread_user[0]
      user_comments = Comment.all().filter('user ='******'-created').fetch(perPage, realPage * perPage)
      comments = helper.filter_user_comments(user_comments, thread_user)
      if (page * perPage) < Comment.all().filter('user ='******'templates/threads.html', locals()))
    else:
      self.redirect('/')
コード例 #38
0
    def post(self, nickname):
        session = get_current_session()
        if session.has_key('user'):
            user = session['user']
            profiledUser = User.all().filter('nickname =', nickname).fetch(1)
            if len(profiledUser) == 1:
                profiledUser = profiledUser[0]
            if user.key() == profiledUser.key():
                about = helper.sanitizeHtml(self.request.get('about'))
                hnuser = helper.sanitizeHtml(self.request.get('hnuser'))
                location = helper.sanitizeHtml(self.request.get('location'))
                github = helper.sanitizeHtml(self.request.get('github'))
                twitter = helper.sanitizeHtml(self.request.get('twitter'))
                email = helper.sanitizeHtml(self.request.get('email'))
                url = helper.sanitizeHtml(self.request.get('url'))

                user.about = about
                user.location = location
                user.github = github
                user.hnuser = hnuser
                user.twitter = twitter
                if len(User.all().filter("email", email).fetch(1)) == 0:
                    try:
                        user.email = email
                    except db.BadValueError:
                        pass
                try:
                    user.url = url
                except db.BadValueError:
                    pass
                user.put()
                my_profile = True
                session['profile_saved'] = True
                self.redirect('/perfil/' + user.nickname)
            else:
                self.redirect('/')
        else:
            self.redirect('/login')
コード例 #39
0
  def post(self,nickname):
    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
      profiledUser = User.all().filter('nickname =',nickname).fetch(1)
      if len(profiledUser) == 1:
        profiledUser = profiledUser[0]
      if user.key() == profiledUser.key():
        about = helper.sanitizeHtml(self.request.get('about'))
        hnuser = helper.sanitizeHtml(self.request.get('hnuser'))
        location = helper.sanitizeHtml(self.request.get('location'))
        github = helper.sanitizeHtml(self.request.get('github'))
        twitter = helper.sanitizeHtml(self.request.get('twitter'))
        email = helper.sanitizeHtml(self.request.get('email'))
        url = helper.sanitizeHtml(self.request.get('url'))

        user.about = about
        user.location = location
        user.github = github
        user.hnuser = hnuser
        user.twitter = twitter
        if len(User.all().filter("email",email).fetch(1)) == 0:
          try:
            user.email = email
          except db.BadValueError:
            pass
        try:
          user.url = url
        except db.BadValueError:
          pass
        user.put()
        my_profile = True
        session['profile_saved'] = True 
        self.redirect('/perfil/' + user.nickname)
      else:
        self.redirect('/')
    else:
      self.redirect('/login')
コード例 #40
0
    def post(self):
        session = get_current_session()
        url = self.request.get('url')
        title = helper.sanitizeHtml(self.request.get('title'))
        message = helper.sanitizeHtml(self.request.get('message'))
        nice_url = helper.sluglify(title)

        if session.has_key('user'):
            if len(nice_url) > 0:
                user = session['user']
                if len(message) == 0:  #is it a post or a message?
                    #Check that we don't have the same URL within the last 'check_days'
                    since_date = date.today() - timedelta(days=7)
                    q = Post.all().filter("created >",
                                          since_date).filter("url =",
                                                             url).count()
                    url_exists = q > 0
                    q = Post.all().filter("nice_url", nice_url).count()
                    nice_url_exist = q > 0
                    try:
                        if not url_exists:
                            if not nice_url_exist:
                                post = Post(url=url,
                                            title=title,
                                            message=message,
                                            user=user,
                                            nice_url=nice_url)
                                post.put()
                                helper.killmetrics("Submit", "Link", "do",
                                                   session, "", self)
                                vote = Vote(user=user,
                                            post=post,
                                            target_user=post.user)
                                vote.put()
                                Post.remove_cached_count_from_memcache()

                                #index with indextank
                                helper.indextank_document(
                                    helper.base_url(self), post)

                                self.redirect('/noticia/' + str(post.nice_url))
                            else:
                                session[
                                    'post_error'] = "Este titulo ha sido usado en una noticia anterior"
                                self.redirect('/agregar')
                        else:
                            session[
                                'post_error'] = "Este link ha sido entregado en los ultimo 7 dias"
                            self.redirect('/agregar')
                    except db.BadValueError:
                        session[
                            'post_error'] = "El formato del link no es valido"
                        self.redirect('/agregar')
                else:
                    q = Post.all().filter("nice_url", nice_url).count()
                    nice_url_exist = q > 0
                    if not nice_url_exist:
                        post = Post(title=title,
                                    message=message,
                                    user=user,
                                    nice_url=nice_url)
                        post.put()
                        helper.killmetrics("Submit", "Post", "do", session, "",
                                           self)
                        post.url = helper.base_url(
                            self) + "/noticia/" + post.nice_url
                        post.put()
                        Post.remove_cached_count_from_memcache()
                        vote = Vote(user=user,
                                    post=post,
                                    target_user=post.user)
                        vote.put()

                        #index with indextank
                        helper.indextank_document(helper.base_url(self), post)

                        self.redirect('/noticia/' + post.nice_url)
                    else:
                        session[
                            'post_error'] = "Este titulo ha sido usado en una noticia anterior"
                        self.redirect('/agregar')
            else:
                session['post_error'] = "Necesitas agregar un titulo"
                self.redirect('/agregar')
        else:
            self.redirect('/login')
コード例 #41
0
  def post(self):
    session = get_current_session()
    url = self.request.get('url')
    title = helper.sanitizeHtml(self.request.get('title'))
    message = helper.sanitizeHtml(self.request.get('message'))
    nice_url = helper.sluglify(title)
    key = self.request.get('comment_key')
 
    if session.has_key('user') and key == keys.comment_key:
      if len(nice_url) > 0:
        user = session['user']
        if len(message) == 0: #is it a post or a message?
          #Check that we don't have the same URL within the last 'check_days'
          since_date = date.today() - timedelta(days=7)
          q = Post.all().filter("created >", since_date).filter("url =", url).count()
          url_exists = q > 0
          q = Post.all().filter("nice_url", nice_url).count()
          nice_url_exist = q > 0
          try:
            if not url_exists:
              if not nice_url_exist:
                post = Post(url=url,title=title,message=message, user=user, nice_url=nice_url)
                post.put()
                helper.killmetrics("Submit","Link", "do", session, "",self)
                vote = Vote(user=user, post=post, target_user=post.user)
                vote.put()
                Post.remove_cached_count_from_memcache()
 	
                #index with indextank
                helper.indextank_document( helper.base_url(self), post)
                
                self.redirect('/noticia/' + str(post.nice_url));
              else:
                session['post_error'] = "Este titulo ha sido usado en una noticia anterior"
                self.redirect('/agregar')
            else:
              session['post_error'] = "Este link ha sido entregado en los ultimo 7 dias"
              self.redirect('/agregar')
          except db.BadValueError:
            session['post_error'] = "El formato del link no es valido"
            self.redirect('/agregar')
        else:
          q = Post.all().filter("nice_url", nice_url).count()
          nice_url_exist = q > 0
          if not nice_url_exist:
            post = Post(title=title,message=message, user=user, nice_url=nice_url)
            post.put()
            helper.killmetrics("Submit","Post", "do", session, "",self)
            post.url = helper.base_url(self) + "/noticia/" + post.nice_url
            post.put()
            Post.remove_cached_count_from_memcache()
            vote = Vote(user=user, post=post, target_user=post.user)
            vote.put()

	    #index with indextank
	    helper.indextank_document( helper.base_url(self), post)
            
	    self.redirect('/noticia/' + post.nice_url);
          else:
            session['post_error'] = "Este titulo ha sido usado en una noticia anterior"
            self.redirect('/agregar')
      else:
        session['post_error'] = "Necesitas agregar un titulo"
        self.redirect('/agregar')
    else:
      self.redirect('/login')