Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Add captcha to article submit form for karma < 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Wesley Moore committed Jan 10, 2011
1 parent d5aaee4 commit cff7667
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion r2/r2/controllers/front.py
Expand Up @@ -514,7 +514,7 @@ def GET_submit(self, url, title, tags):
if redirect_link:
return self.redirect(redirect_link.already_submitted_link)

captcha = Captcha() if c.user.needs_captcha() else None
captcha = Captcha(tabular=False) if c.user.needs_captcha() else None
srs = Subreddit.submit_sr(c.user) if c.default_sr else ()

# Set the default sr to the user's draft when creating a new article
Expand Down
4 changes: 2 additions & 2 deletions r2/r2/lib/pages/pages.py
Expand Up @@ -840,10 +840,10 @@ class ResetPassword(Wrapped):

class Captcha(Wrapped):
"""Container for rendering robot detection device."""
def __init__(self, error=None):
def __init__(self, error=None, tabular=True, label=True):
self.error = _('Try entering those letters again') if error else ""
self.iden = get_captcha()
Wrapped.__init__(self)
Wrapped.__init__(self, tabular=tabular, label=label)

class CommentReplyBox(Wrapped):
"""Used on LinkInfoPage to render the comment reply form at the
Expand Down
4 changes: 1 addition & 3 deletions r2/r2/models/account.py
Expand Up @@ -204,9 +204,7 @@ def make_cookie(self, timestr = None, admin = False):
return id_time + ',' + hashlib.sha1(to_hash).hexdigest()

def needs_captcha(self):
# TODO: decide on who/what/why needs a captcha
return False
# return self.link_karma < 1
return self.safe_karma < 1

def modhash(self, rand=None, test=False):
return modhash(self, rand = rand, test = test)
Expand Down
7 changes: 7 additions & 0 deletions r2/r2/public/static/lesswrong.css
Expand Up @@ -529,3 +529,10 @@ div.comment div.parent {
color: red
}

/* Submit form */
.pretty-form.long-text .cap-reply {
display: block;
}
.pretty-form.long-text #captcha {
width: 250px;
}
8 changes: 4 additions & 4 deletions r2/r2/templates/captcha.html
Expand Up @@ -23,7 +23,7 @@
<%! from r2.lib.template_helpers import static %>

<%namespace file="utils.html" import="error_field"/>
${captchagen(thing.iden, thing.error)}
${captchagen(thing.iden, thing.error, tabular=thing.tabular, label=thing.label)}

<%def name="captchagen(iden, error='', tabulate=False, tabular = True, size=60, label=True, show_error = True)">
%if tabulate:
Expand Down Expand Up @@ -51,9 +51,6 @@
%else:
<span class="cap-reply">
%endif
%if label:
<label for="captcha">${_("Human?")}</label>
%endif
%if tabular:
</td>
<td>
Expand All @@ -64,6 +61,9 @@
<script type="text/javascript">
setMessage($('captcha'), "${_('Type the letters from the image above')}");
</script>
%if label:
<label for="captcha">${_('Type the letters from the image above.')}</label>
%endif
%if tabular:
</td>
<td>
Expand Down
6 changes: 5 additions & 1 deletion r2/r2/templates/newlink.html
Expand Up @@ -86,7 +86,11 @@ <h1>${_("Submit article to %(site)s") % dict(site=c.site.name)}</h1>
</tr>
%endif
%if thing.captcha:
${thing.captcha.render()}
<tr>
<td>
${thing.captcha.render()}
</td>
</tr>
%endif
<tr>
<td>
Expand Down

0 comments on commit cff7667

Please sign in to comment.