diff src/api/change_email.json.luan @ 57:169ac5fdb320

add change email
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 28 Nov 2022 23:47:19 -0700
parents src/api/login_email.json.luan@260abd8f8565
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/api/change_email.json.luan	Mon Nov 28 23:47:19 2022 -0700
@@ -0,0 +1,33 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local Html = require "luan:Html.luan"
+local url_encode = Html.url_encode or error()
+local Io = require "luan:Io.luan"
+local output_of = Io.output_of or error()
+local Http = require "luan:http/Http.luan"
+local Mail = require "site:/lib/Mail.luan"
+local Api = require "site:/api/Api.luan"
+local api = Api.api or error()
+local user_error = Api.user_error or error()
+
+
+return api(function()
+	local base_url = Http.request.parameters.base_url or user_error "missing base_url param"
+	local from = Http.request.parameters.from or user_error "missing from param"
+	local email = Http.request.parameters.email or user_error "missing email param"
+	local password = Http.request.parameters.password or user_error "missing password param"
+	local mailer = Mail.sender() or user_error "mail not configured"
+	mailer.send{
+		From = from
+		To = email
+		Subject = "Change Email"
+		body = output_of(function() %>
+Change your email address to this email by clicking this link:
+
+<%=base_url%>/change_email.html?email=<%=url_encode(email)%>&password=<%=password%>
+<%		end)
+	}
+	return {
+		okay = true
+	}
+end)