1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01:00
antd-web-apps/grs/subscribe.lua
2018-10-10 14:35:00 +02:00

22 lines
598 B
Lua

if not REQUEST.json then
fail("unknown request")
end
local rq = (JSON.decodeString(REQUEST.json))
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