Skip to content

Commit

Permalink
Add config for requiring emails
Browse files Browse the repository at this point in the history
  • Loading branch information
NickHu committed Aug 25, 2015
1 parent 5d21e1b commit cd54cf1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ In chronological order:
* Daniel Gräber <https://github.com/albohlabs>
* Added ansible for provisioning

* Nick Hu <https://github.com/NickHu>
* Added configuration to require email addresses (no validation)

* [Your name or handle] <[email or website]>
* [Brief summary of your changes]
6 changes: 6 additions & 0 deletions docs/docs/configuration/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ preferably in the script tag which embeds the JS:
data-isso-css="true"
data-isso-lang="ru"
data-isso-reply-to-self="false"
data-isso-require-email="false"
data-isso-max-comments-top="10"
data-isso-max-comments-nested="5"
data-isso-reveal-on-click="5"
Expand Down Expand Up @@ -58,6 +59,11 @@ data-isso-reply-to-self

Set to `true` when spam guard is configured with `reply-to-self = true`.

data-isso-require-email
-----------------------

Set to `true` when spam guard is configured with `require-email = true`.

data-isso-max-comments-top and data-isso-max-comments-nested
------------------------------------------------------------

Expand Down
7 changes: 7 additions & 0 deletions docs/docs/configuration/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ for IPv4, ``/48`` for IPv6).
ratelimit = 2
direct-reply = 3
reply-to-self = false
require-email = false
enabled
enable guard, recommended in production. Not useful for debugging
Expand All @@ -236,6 +237,12 @@ reply-to-self

Do not forget to configure the client.

require-email
force commenters to enter a value into the email field. No validation is
performed on the provided value.

Do not forget to configure the client.

Markup
------

Expand Down
12 changes: 12 additions & 0 deletions isso/db/spam.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _limit(self, uri, comment):
if len(rv) >= self.conf.getint("direct-reply"):
return False, "%i direct responses to %s" % (len(rv), uri)

# block replies to self unless :param:`reply-to-self` is enabled
elif self.conf.getboolean("reply-to-self") == False:
rv = self.db.execute([
'SELECT id FROM comments WHERE'
Expand All @@ -61,6 +62,17 @@ def _limit(self, uri, comment):
if len(rv) > 0:
return False, "edit time frame is still open"

# require email if :param:`require-email` is enabled
if self.conf.getboolean("require-email") == True:
rv = self.db.execute([
'SELECT id FROM comments WHERE'
' remote_addr = ?',
'AND email IS NULL;'
], (comment["remote_addr"],)).fetchall()

if len(rv) > 0:
return False, "email address required but not provided"

return True, ""

def _spam(self, uri, comment):
Expand Down
1 change: 1 addition & 0 deletions isso/js/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define(function() {
"css": true,
"lang": (navigator.language || navigator.userLanguage).split("-")[0],
"reply-to-self": false,
"require-email": false,
"max-comments-top": "inf",
"max-comments-nested": 5,
"reveal-on-click": 5,
Expand Down
13 changes: 13 additions & 0 deletions isso/js/app/isso.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,22 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
$(".textarea", this).focus();
return false;
}
if (config["require-email"] &&
$("[name='email']", this).value.length <= 0)
{
$("[name='email']", this).focus();
return false;
}
return true;
};

// email is not optional if this config parameter is set
if (config["require-email"])
{
$("[name='email']", el).placeholder =
$("[name='email']", el).placeholder.replace(/ \(.*\)/, "");
}

// submit form, initialize optional fields with `null` and reset form.
// If replied to a comment, remove form completely.
$("[type=submit]", el).on("click", function() {
Expand Down
9 changes: 8 additions & 1 deletion isso/tests/test_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestGuard(unittest.TestCase):
def setUp(self):
self.path = tempfile.NamedTemporaryFile().name

def makeClient(self, ip, ratelimit=2, direct_reply=3, self_reply=False):
def makeClient(self, ip, ratelimit=2, direct_reply=3, self_reply=False, require_email=False):

conf = config.load(os.path.join(dist.location, "share", "isso.conf"))
conf.set("general", "dbpath", self.path)
Expand All @@ -44,11 +44,13 @@ def makeClient(self, ip, ratelimit=2, direct_reply=3, self_reply=False):
conf.set("guard", "ratelimit", str(ratelimit))
conf.set("guard", "direct-reply", str(direct_reply))
conf.set("guard", "reply-to-self", "1" if self_reply else "0")
conf.set("guard", "require-email", "1" if require_email else "0")

class App(Isso, core.Mixin):
pass

app = App(conf)

app.wsgi_app = FakeIP(app.wsgi_app, ip)

return Client(app, Response)
Expand Down Expand Up @@ -113,3 +115,8 @@ def testSelfReply(self):
self.assertEqual(client.post("/new?uri=test", data=self.data).status_code, 201)
self.assertEqual(client.post("/new?uri=test", data=payload(1)).status_code, 201)
self.assertEqual(client.post("/new?uri=test", data=payload(2)).status_code, 201)

def testRequireEmail(self):

#TODO
pass
4 changes: 4 additions & 0 deletions share/isso.conf
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ direct-reply = 3
# their own comments anyways. Do not forget to configure the client.
reply-to-self = false

# require the commenter to enter an email address (note: no validation is
# done on the provided address). Do not forget to configure the client.
require-email = false


[markup]
# Customize markup and sanitized HTML. Currently, only Markdown (via Misaka) is
Expand Down

0 comments on commit cd54cf1

Please # to comment.