Hidden command to allow jmp-register to start a web registration

Stephen Paul Weber created

This is the command jmp-register will use to tell use a certain claimed JID
wants a certain tel.  We relay that to cheogram and save in web_register_manager
the tel associated with the JID cheogram assigns to the target.

Change summary

config.dhall.sample |  4 ++++
sgx_jmp.rb          | 22 ++++++++++++++++++++++
2 files changed, 26 insertions(+)

Detailed changes

config.dhall.sample 🔗

@@ -19,6 +19,10 @@
 		secret = "",
 		application_id = ""
 	},
+	web_register = {
+		to = "cheogram",
+		from = "jmp-register@localhost"
+	},
 	bandwidth_site = "",
 	braintree = {
 		environment = "sandbox",

sgx_jmp.rb 🔗

@@ -225,6 +225,28 @@ command :execute?, node: "buy-credit", sessionid: nil do |iq|
 	}.catch(&method(:panic))
 end
 
+command :execute?, node: "web-register", sessionid: nil do |iq|
+	jid = iq.form.field("jid")&.value.to_s.strip
+	tel = iq.form.field("tel")&.value.to_s.strip
+	if iq.from.stripped != CONFIG[:web_register][:from]
+		BLATHER << iq.as_error("forbidden", :auth)
+	elsif jid == "" || tel !~ /\A\+\d+\Z/
+		reply_with_note(iq, "Invalid JID or telephone number.", type: :error)
+	else
+		IQ_MANAGER.write(Blather::Stanza::Iq::Command.new.tap { |cmd|
+			cmd.to = CONFIG[:web_register][:to]
+			cmd.from = CONFIG[:component][:jid]
+			cmd.node = "push-register"
+			cmd.form.fields = [var: "to", value: jid]
+			cmd.form.type = "submit"
+		}).then do |result|
+			final_jid = result.form.field("from")&.value.to_s.strip
+			web_register_manager[final_jid] = tel
+			BLATHER << iq.reply.tap { |reply| reply.status = :completed }
+		end
+	end
+end
+
 command sessionid: /./ do |iq|
 	COMMAND_MANAGER.fulfill(iq)
 end