Skip to content

Commit

Permalink
评论验证
Browse files Browse the repository at this point in the history
  • Loading branch information
dengmin committed Jan 11, 2013
1 parent fc4fe9e commit 4b7f1a9
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

DEBUG = True

BLOG_NAME = u'Logpress'
SITE_NAME = u'Logpress'
SITE_KEYWORDS=""""""
SITE_DESC= """blog powered by tornado,jinja2,peewee"""
DOMAIN='http://0.0.0.0:9000'
Expand All @@ -21,5 +21,5 @@
SMTP_SERVER ='smtp.qq.com'
SMTP_PORT = 587
SMTP_USER = '[email protected]'
SMTP_PASSWORD = ''
SMTP_PASSWORD = 'xxxxxx'
SMTP_USETLS = True
2 changes: 1 addition & 1 deletion core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
jinja_environment = Environment(
loader = FileSystemLoader(settings['template_path']),
auto_reload = settings['debug'],
autoescape = True)
autoescape = False)

db = Database({'db':settings['db_name'],'engine':settings['db_engine']})

Expand Down
10 changes: 9 additions & 1 deletion handlers/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def get(self,postid):
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
r')@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$', re.IGNORECASE)

_url_re = re.compile(r'(http://[^/\\]+)', re.I)

class PostCommentHandler(BaseHandler):

@property
Expand All @@ -138,10 +140,16 @@ def post(self):
if postid:
post = Post.get(id=int(postid))
if author and email and comment:
if len(author) >18:
self.flash('UserName is too long.')
return self.redirect("%s#respond"%(post.url))
if not _email_re.match(email):
self.flash(u'Email address is invalid.')
return self.redirect("%s#respond"%(post.url))

if url and not _url_re.match(url):
self.flash(u'website is invalid.')
return self.redirect("%s#respond"%(post.url))

comment = Comment.create(post=post,ip=self.request.remote_ip,
author=author,email=email,website=url,
content=comment,parent_id=parent_id)
Expand Down
4 changes: 4 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def url(self):
@property
def absolute_url(self):
return '%s%s'%(domain,self.url)

@property
def comment_feed(self):
return '%s/archive/%s/feed'(domain,self.id)

@cached_property
def prev(self):
Expand Down
6 changes: 3 additions & 3 deletions templates/baidu.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<document>
<webSite>{{settings.domain}}</webSite>
<webMaster>{{settings.blog_name}}</webMaster>
<webMaster>{{settings.site_name}}</webMaster>
<updatePeri>1800</updatePeri>
{% for post in posts%}
<item>
Expand All @@ -10,8 +10,8 @@
<text>{{post.summary|markdown}}</text>
<image></image>
<keywords>{{post.tags}}</keywords>
<author>{{settings.blog_name}}</author>
<source>{{settings.blog_name}}</source>
<author>{{settings.site_name}}</author>
<source>{{settings.site_name}}</source>
<pubDate>{{post.created|datetimeformat}}</pubDate>
</item>
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions templates/comment_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<rss version='2.0'>
<channel>
<title><![CDATA[Comments on:{{post.title}}]]></title>
<atom:link href="{{settings.domain}}/archive/{{post.id}}/feed" rel="self" type="application/rss+xml" />
<atom:link href="{{post.comment_feed}}" rel="self" type="application/rss+xml" />
<description><![CDATA[{{settings.site_desc}}]]></description>
<link>{{settings.domain}}</link>
<language>zh-cn</language>
<lastBuildDate>Wed, 19 Dec 2012 01:26:06 +0000</lastBuildDate>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>Rss Powered By {{settings.blog_name}}</generator>
<generator>Rss Powered By {{settings.site_name}}</generator>

{% for comment in post.comments %}
<item>
Expand Down
8 changes: 4 additions & 4 deletions templates/default/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>{{settings.blog_name}}</title>
<title>{{settings.site_name}}</title>
<link rel="stylesheet" type="text/css" media="all" href="{{static('default/style.css')}}" />
<link rel="pingback" href="" />
<link rel="alternate" type="application/rss+xml" title="{{settings.blog_name}} &raquo; Feed" href="/feed" />
<link rel="alternate" type="application/rss+xml" title="{{settings.site_name}} &raquo; Feed" href="/feed" />

</head>
<body class="home blog">
<div id="header-wrap">
<div id="header">
<div class="h_top">
<h1><a href="{{settings.domain}}" title="{{settings.blog_name}}">{{settings.blog_name}}</a></h1>
<h1><a href="{{settings.domain}}" title="{{settings.site_name}}">{{settings.site_name}}</a></h1>
<p>blog</p>
</div>
<div class="h_bottom">
Expand All @@ -50,7 +50,7 @@ <h1><a href="{{settings.domain}}" title="{{settings.blog_name}}">{{settings.blog
{% endblock %}
<div id="footer">
<div id="copyright">
©2013 <a href="{{settings.doamin}}" title="{{settings.blog_name}}">{{settings.blog_name}}</a> All rights reserved. {% set request_time = 1000.0 * request.request_time() %}
©2013 <a href="{{settings.doamin}}" title="{{settings.site_name}}">{{settings.site_name}}</a> All rights reserved. {% set request_time = 1000.0 * request.request_time() %}
<span class="label-success">{{"%.2f ms" % request_time}}</span>
</div>
<p class="daxiawp">
Expand Down
8 changes: 4 additions & 4 deletions templates/feed.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<rss version='2.0'>
<channel>
<title><![CDATA[{{settings.blog_name}}]]></title>
<title><![CDATA[{{settings.site_name}}]]></title>
<description><![CDATA[{{settings.site_desc}}]]></description>
<link>{{settings.domain}}</link>
<language>zh-cn</language>
<docs>{{settings.blog_name}}</docs>
<docs>{{settings.site_desc}}</docs>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>Rss Powered By {{settings.blog_name}}</generator>
<generator>Rss Powered By {{settings.site_name}}</generator>
{% for post in posts%}
<item>
<title><![CDATA[{{post.title}}]]></title>
Expand All @@ -17,7 +17,7 @@
<pubDate>{{post.created|datetimeformat}}</pubDate>
<category><![CDATA[{{post.category.name}}]]></category>
<description><![CDATA[{{post.content|markdown}}]]></description>
<wfw:commentRss>{{settings.domain}}/archive/{{post.id}}/feed</wfw:commentRss>
<wfw:commentRss>{{post.comment_feed}}</wfw:commentRss>
<slash:comments>{{post.comments.count()}}</slash:comments>
</item>
{% endfor %}
Expand Down
5 changes: 3 additions & 2 deletions templates/fluid-blue/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="robots" content="index, follow" />
<title>{%block title%}{%endblock%} {{settings.blog_name}}</title>
<title>{%block title%}{%endblock%} {{settings.site_name}}</title>
<meta name="Keywords" content="{{settings.site_keywords}}"/>
<meta name="Description" content="{{settings.site_desc}}"/>
<link rel="stylesheet" href="{{static('fluid/style.css')}}" type="text/css" media="screen" />
Expand All @@ -17,7 +17,7 @@
<div id="page">
<div id="header">
<div id="headertitle">
<h1><a href="/" title="{{settings.blog_name}}: {{settings.site_desc}}">{{settings.blog_name}}</a></h1>
<h1><a href="/" title="{{settings.site_name}}: {{settings.site_desc}}">{{settings.site_name}}</a></h1>
<p>{{settings.site_desc}}</p>
</div>
<!-- Search box (If you prefer having search form as a sidebar widget, remove this block) -->
Expand All @@ -41,6 +41,7 @@ <h1><a href="/" title="{{settings.blog_name}}: {{settings.site_desc}}">{{setting
{%endblock%}
</div> <!-- wrapper -->
<div id="footer">
©2013 <a href="https://github.com/dengmin/logpress-tornado" title="Logpress" target="_blank">Logpress</a>.
<a href="/feed">RSS</a>. Valid <a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional"><abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a> and <a href="http://jigsaw.w3.org/css-validator/check/referer"><abbr title="Cascading Style Sheets">CSS</abbr></a>.<br />
Powered by <a href="http://www.tornadoweb.org/" target='_blank'>Tornado</a> and <a href="http://srinig.com/wordpress/themes/fluid-blue/">Fluid Blue theme</a>.<br />
</div>
Expand Down

0 comments on commit 4b7f1a9

Please sign in to comment.