Beispiel #1
0
 def get(self):
     img = Image()
     imgdata = img.create()
     sess = Session(self, timeout=900)
     if not sess.is_new():
         sess.invalidate()
         sess = Session(self, timeout=900)
     sess['code'] = img.text
     sess.save()
     self.response.headers['Content-Type'] = "image/png"
     self.response.out.write(imgdata)
Beispiel #2
0
 def get(self):
     sess=Session(self,timeout=900)
     num1=random.randint(30,50)
     num2=random.randint(1,10)
     code="<span style='font-size:12px;color:red'>%d - %d =</span>"%(num1,num2)
     sess['code']=num1-num2
     sess.save()
     #self.response.headers['Content-Type'] = "text/html"
     self.response.out.write(code)
Beispiel #3
0
    def post(self, slug=None):
        useajax = self.param('useajax') == '1'

        name = self.param('author')
        email = self.param('email')
        url = self.param('url')

        key = self.param('key')
        content = self.param('comment')
        parent_id = self.paramint('parentid', 0)
        reply_notify_mail = self.parambool('reply_notify_mail')

        sess = Session(self, timeout=180)
        if not self.is_login:
            #if not (self.request.cookies.get('comment_user', '')):
            try:
                check_ret = True
                if g_blog.comment_check_type in (1, 2):
                    checkret = self.param('checkret')
                    check_ret = (int(checkret) == sess['code'])
                elif g_blog.comment_check_type == 3:
                    import app.gbtools as gb
                    checknum = self.param('checknum')
                    checkret = self.param('checkret')
                    check_ret = eval(checknum) == int(gb.stringQ2B(checkret))

                if not check_ret:
                    if useajax:
                        self.write(
                            simplejson.dumps(
                                (False, -102,
                                 _('Your check code is invalid .')),
                                ensure_ascii=False))
                    else:
                        self.error(-102, _('Your check code is invalid .'))
                    return
            except:
                if useajax:
                    self.write(
                        simplejson.dumps(
                            (False, -102, _('Your check code is invalid .')),
                            ensure_ascii=False))
                else:
                    self.error(-102, _('Your check code is invalid .'))
                return

        sess.invalidate()
        content = content.replace('\n', '<br />')
        content = myfilter.do_filter(content)
        name = cgi.escape(name)[:20]
        url = cgi.escape(url)[:100]

        if not (name and email and content):
            if useajax:
                self.write(
                    simplejson.dumps(
                        (False, -101,
                         _('Please input name, email and comment .'))))
            else:
                self.error(-101, _('Please input name, email and comment .'))
        else:
            comment = Comment(author=name,
                              content=content,
                              email=email,
                              reply_notify_mail=reply_notify_mail,
                              entry=Entry.get(key))
            if url:
                try:
                    if not url.lower().startswith(('http://', 'https://')):
                        url = 'http://' + url
                    comment.weburl = url
                except:
                    comment.weburl = None

            #name=name.decode('utf8').encode('gb2312')

            info_str = '#@#'.join(
                [urlencode(name),
                 urlencode(email),
                 urlencode(url)])

            #info_str='#@#'.join([name,email,url.encode('utf8')])
            cookiestr = 'comment_user=%s;expires=%s;path=/;' % (info_str, (
                datetime.now() +
                timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"))
            comment.ip = self.request.remote_addr

            if parent_id:
                comment.parent = Comment.get_by_id(parent_id)

            comment.no = comment.entry.commentcount + 1
            try:
                comment.save()
                memcache.delete("/" + comment.entry.link)

                self.response.headers.add_header('Set-Cookie', cookiestr)
                if useajax:
                    comment_c = self.get_render('comment',
                                                {'comment': comment})
                    self.write(
                        simplejson.dumps((True, comment_c.decode('utf8')),
                                         ensure_ascii=False))
                else:
                    self.redirect(self.referer + "#comment-" +
                                  str(comment.key().id()))

                comment.entry.removecache()
                memcache.delete("/feed/comments")
            except:
                if useajax:
                    self.write(
                        simplejson.dumps(
                            (False, -102, _('Comment not allowed.'))))
                else:
                    self.error(-102, _('Comment not allowed .'))