ikibooru/smtpauth.lua
2024-06-01 17:40:11 +03:00

61 lines
2.2 KiB
Lua

local DB = require"db"
local Escapes = require"html"
local BigGlobe = require"bigglobe"
local Rand = require"openssl.rand"
assert(Rand.ready())
local DB = require"db"
local function sendeml(raw)
--[[local fn = "/tmp/ikibooru" .. DB.b256toreadable(Rand.bytes(16)) .. ".eml"
local f = io.open(fn, "wb")
f:write(raw)
f:close()
-- Send e-mail. Yes, this is crude.
io.popen("{ sendmail -t < " .. fn .. "; rm " .. fn .. "; } &", "r")]]
end
return {
sendauthinfo = function(user)
local url = BigGlobe.cfg.domain .."/verif?q=" .. Escapes.urlescape(DB.userauth(user))
-- print(url)
if BigGlobe.cfg.anarchy == "ANARCHY" then
return url
else
sendeml(string.format([[To: %s
Subject: %s sign-in via e-mail
Content-Type: text/html; charset=UTF-8
MIME-Version: 1.0
<!DOCTYPE html>
<html><body style="font-family:sans-serif;"><p>Welcome back to %s. Click on the below link to access your account.</p><p>If you had not initiated a sign-in request, consider whether your e-mail account has been compromised.</p><a href="%s"><div style="display:inline-block;font-size:1.2em;padding:0.5em 1em 0.5em 1em;border:1px solid gray;color:#C0C0C0;border-radius:6px;"><span>Sign-in</span></div></a></body></html>]], user.email, BigGlobe.cfg.sitename, BigGlobe.cfg.sitename, url))
return true
end
end,
sendregisterinfo = function(user)
local url = BigGlobe.cfg.domain .."/reg?q=" .. Escapes.urlescape(DB.userregcode(user))
print(url)
if BigGlobe.cfg.anarchy == "ANARCHY" then
return url
else
sendeml(string.format([[To: %s
Subject: %s registration via e-mail
Content-Type: text/html; charset=UTF-8
MIME-Version: 1.0
<!DOCTYPE html>
<html><body style="font-family:sans-serif;"><p>You have either registered or been invited to register at %s. Click on the below link to complete your registration.</p><p>If you have no idea what this is, consider whether your e-mail account has been compromised.</p><a href="%s"><div style="display:inline-block;font-size:1.2em;padding:0.5em 1em 0.5em 1em;border:1px solid gray;color:#C0C0C0;border-radius:6px;"><span>Complete</span></div></a></body></html>]], user.email, BigGlobe.cfg.sitename, BigGlobe.cfg.sitename, url))
return true
end
end
}