From 35181f164ffe5ac6adf7ce061184d70563cd4fcb Mon Sep 17 00:00:00 2001 From: Christopher Slowe Date: Sat, 16 Aug 2008 21:36:56 -0700 Subject: [PATCH] added captcha to message composition --- r2/r2/controllers/api.py | 6 +++++- r2/r2/controllers/listingcontroller.py | 17 +++++++++++------ r2/r2/lib/pages/pages.py | 10 +++++++--- r2/r2/templates/messagecompose.html | 3 +++ r2/r2/templates/newlink.html | 2 +- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 22ab96bbb..843d1f989 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -137,7 +137,8 @@ class ApiController(RedditController): POST_ad_inq = POST_feedback @Json - @validate(VUser(), + @validate(VCaptcha(), + VUser(), VModhash(), ip = ValidIP(), to = VExistingUname('to'), @@ -153,6 +154,9 @@ class ApiController(RedditController): elif (res._chk_error(errors.NO_MSG_BODY) or res._chk_error(errors.COMMENT_TOO_LONG)): res._focus('message') + elif res._chk_captcha(errors.BAD_CAPTCHA): + pass + if not res.error: spam = (c.user._spam or errors.BANNED_IP in c.errors or diff --git a/r2/r2/controllers/listingcontroller.py b/r2/r2/controllers/listingcontroller.py index ac96d581c..c468190cb 100644 --- a/r2/r2/controllers/listingcontroller.py +++ b/r2/r2/controllers/listingcontroller.py @@ -425,12 +425,17 @@ class MessageController(ListingController): c.msg_location = where return ListingController.GET_listing(self, **env) - def GET_compose(self): - i = request.get - if not c.user_is_loggedin: return self.abort404() - content = MessageCompose(to = i.get('to'), subject = i.get('subject'), - message = i.get('message'), - success = i.get('success')) + @validate(VUser(), + to = nop('to'), + subject = nop('subject'), + message = nop('message'), + success = nop('success')) + def GET_compose(self, to, subject, message, success): + captcha = Captcha() if c.user.needs_captcha() else None + content = MessageCompose(to = to, subject = subject, + captcha = captcha, + message = message, + success = success) return MessagePage(content = content).render() diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index a0724a5d0..5cec720b8 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -95,7 +95,7 @@ class Reddit(Wrapped): self.subreddit_sidebox = True self.subreddit_checkboxes = c.site == Default - if c.user_is_loggedin: + if c.user_is_loggedin and self.show_sidebar: self._content = PaneStack([ShareLink(), content]) else: self._content = content @@ -300,6 +300,8 @@ class PrefDelete(Wrapped): class MessagePage(Reddit): """Defines the content for /message/*""" def __init__(self, *a, **kw): + if not kw.has_key('show_sidebar'): + kw['show_sidebar'] = False Reddit.__init__(self, *a, **kw) self.replybox = CommentReplyBox() @@ -316,9 +318,11 @@ class MessagePage(Reddit): class MessageCompose(Wrapped): """Compose message form.""" - def __init__(self,to='', subject='', message='', success=''): + def __init__(self,to='', subject='', message='', success='', + captcha = None): Wrapped.__init__(self, to = to, subject = subject, - message = message, success = success) + message = message, success = success, + captcha = captcha) class BoringPage(Reddit): diff --git a/r2/r2/templates/messagecompose.html b/r2/r2/templates/messagecompose.html index 748e04beb..1debe4e16 100644 --- a/r2/r2/templates/messagecompose.html +++ b/r2/r2/templates/messagecompose.html @@ -60,6 +60,9 @@ ${success_field(_("your message has been delivered"), ${error_field("NO_MSG_BODY", "span")} ${error_field("COMMENT_TOO_LONG", "span")} + %if thing.captcha: + ${thing.captcha.render()} + %endif diff --git a/r2/r2/templates/newlink.html b/r2/r2/templates/newlink.html index aef3e9ac5..22e948eae 100644 --- a/r2/r2/templates/newlink.html +++ b/r2/r2/templates/newlink.html @@ -1,4 +1,4 @@ -## "The contents of this file are subject to the Common Public Attribution +## The contents of this file are subject to the Common Public Attribution ## License Version 1.0. (the "License"); you may not use this file except in ## compliance with the License. You may obtain a copy of the License at ## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public