~singpolyma/sgx-jmp

9fcf88ec8643c60ca7d38c8da9427a50b501fe70 — Stephen Paul Weber 3 years ago 5208fbd + a35d429
Merge branch 'web-register-start'

* web-register-start:
  Hidden command to allow jmp-register to start a web registration
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