examples/mc_register.lua
changeset 67 d33ca5572e91
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/mc_register.lua	Sat Mar 28 19:43:12 2009 +0200
@@ -0,0 +1,81 @@
+
+local lm          = require 'lm'
+local iq_register = require 'iq_register'
+
+main.command ( 'register',
+	function ( args )
+		local who
+		if args and args ~= '' then
+			who = args
+		else
+			who = main.full_jid ()
+		end
+		iq_register.register ( lm.connection.bless ( main.connection () ), who,
+			function ( form, submit, reject )
+				insert_form ( form,
+					function ( form )
+						submit ( form,
+							function ()
+								main.print_info ( who, 'Successfully registered' )
+							end,
+							function ( mesg )
+								main.print_info ( who, 'Registration failed: ' .. mesg )
+							end )
+					end,
+					function ( form )
+						reject ( form,
+							function ()
+								main.print_info ( who, 'Registration cancelled' )
+							end,
+							function ( mesg )
+								main.print_info ( who, 'Registration cancellation failed: ' .. mesg )
+							end )
+					end )
+			end,
+			function ( mesg )
+				main.print_info ( who, 'Registration failed: ' .. mesg )
+			end )
+	end, false, 'jid' )
+main.command ( 'cancel',
+	function ( args )
+		local who
+		if args and args ~= '' then
+			who = args
+		else
+			who = main.full_jid ()
+		end
+		iq_register.unregister ( lm.connection.bless ( main.connection () ), who,
+			function ( form, submit, reject )
+				if not form then
+					main.print_info ( who, 'Successfully unregistered' )
+				else
+					insert_form ( form,
+						function ( form )
+							submit ( form,
+								function ()
+									main.print_info ( who, 'Successfully unregistered' )
+								end,
+								function ( mesg )
+									main.print_info ( who, 'Unregistrering failed: ' .. mesg )
+								end )
+						end,
+						function ( form )
+							reject ( form,
+								function ()
+									main.print_info ( who, 'Unregistration cancelled' )
+								end,
+								function ( mesg )
+									main.print_info ( who, 'Unregistration cancellation failed: ' .. mesg )
+								end )
+						end )
+				end
+			end,
+			function ( mesg )
+				main.print_info ( who, 'Unregistering failed: ' .. mesg )
+			end )
+	end, false, 'jid' )
+
+commands_help['register'] = "[jid]\n\nSends registration request to jid (or current buddy). You, probably, then will need to fill and send some form."
+commands_help['cancel'] = "[jid]\n\nSends registration cancellation request to jid (or current buddy). May require a form filling."
+
+-- vim: se ts=4: --