2018-06-05 16:28:53 +02:00
|
|
|
|
2018-10-10 14:35:00 +02:00
|
|
|
if not REQUEST.json then
|
2018-06-05 16:28:53 +02:00
|
|
|
fail("unknown request")
|
|
|
|
end
|
2018-10-10 14:35:00 +02:00
|
|
|
local rq = (JSON.decodeString(REQUEST.json))
|
2018-06-05 16:28:53 +02:00
|
|
|
local sample = {name = "toto", email = "toto@mail.fr"}
|
|
|
|
local db = require("db.model").get("mrsang","subscribers",sample)
|
|
|
|
|
|
|
|
if db then
|
|
|
|
-- check if email is exist
|
|
|
|
local data = db:find({exp = { ["="] = { email = rq.email } }})
|
|
|
|
if data and #data > 0 then
|
|
|
|
fail("You are already/previously subscribed")
|
|
|
|
else
|
|
|
|
-- save to database
|
|
|
|
db:insert(rq)
|
|
|
|
result("Ok")
|
|
|
|
end
|
|
|
|
db:close()
|
|
|
|
else
|
|
|
|
fail("Cannot subscribe at the moment, the service may be down")
|
|
|
|
end
|