1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2025-07-24 01:29:48 +02:00
This commit is contained in:
Xuan Sang LE
2018-09-05 19:07:37 +02:00
parent 914bff3498
commit 9d8e0916a2
8 changed files with 199 additions and 7 deletions

View File

@ -161,7 +161,7 @@ function PostController:analyse(n)
end
self.template:set(message, "Analyse complete")
else
self.template:set(message, "Cannotto analyse")
self.template:set(message, "Cannot analyse")
end
return true
end

View File

@ -0,0 +1,57 @@
BaseController:subclass(
"ServiceController",
{
registry = {},
models = {"subscribers"}
}
)
function fail(msg)
std.json()
std.t(JSON.encode({error = msg}))
end
function result(obj)
std.json()
std.t(JSON.encode({result = obj, error = false}))
end
function ServiceController:sendmail()
if not REQUEST.query.json then
fail("unknown request")
end
local rq = (JSON.decodeString(REQUEST.query.json))
local to = "xsang.le@gmail.com"
local from = "From: " .. rq.email .. "\n"
local suject = "Subject: " .. rq.subject .. "\n"
local content = "Contact request from:" .. rq.name .. "\n Email: " .. rq.email .. "\n" .. rq.content .. "\n"
local cmd = 'echo "' .. utils.escape(from .. suject .. content) .. '"| sendmail ' .. to
--print(cmd)
local r = os.execute(cmd)
if r then
result(r)
else
fail("Cannot send email at the moment, the service may be down")
end
return false
end
function ServiceController:subscribe()
if not REQUEST.query.json then
fail("unknown request")
end
local rq = (JSON.decodeString(REQUEST.query.json))
-- check if email is exist
local data = self.subscribers:find({exp = {["="] = {email = rq.email}}})
if data and #data > 0 then
fail("You are already/previously subscribed")
else
-- save to database
self.subscribers:create(rq)
result("Ok")
end
return false
end