mirror of
https://github.com/lxsang/antd-web-apps
synced 2025-07-24 01:29:48 +02:00
fix blog
This commit is contained in:
@ -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
|
||||
|
57
blog/controllers/ServiceController.lua
Normal file
57
blog/controllers/ServiceController.lua
Normal 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
|
Reference in New Issue
Block a user