~singpolyma/sgx-jmp

a35d4293d6864f6efe14f5f70db7c65b8cabc9e4 — Stephen Paul Weber 1 year, 4 months ago a0bb2b9
Hidden command to allow jmp-register to start a web registration

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.
2 files changed, 26 insertions(+), 0 deletions(-)

M config.dhall.sample
M sgx_jmp.rb
M config.dhall.sample => config.dhall.sample +4 -0
@@ 19,6 19,10 @@
		secret = "",
		application_id = ""
	},
	web_register = {
		to = "cheogram",
		from = "jmp-register@localhost"
	},
	bandwidth_site = "",
	braintree = {
		environment = "sandbox",

M sgx_jmp.rb => sgx_jmp.rb +22 -0
@@ 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