examples/register.lua
changeset 99 ed4676536ed9
parent 68 742878c74b8e
child 121 75a7d595817c
equal deleted inserted replaced
98:59aeae623ac6 99:ed4676536ed9
     2 local lm          = require 'lm'
     2 local lm          = require 'lm'
     3 local iq_register = require 'lm.iq_register'
     3 local iq_register = require 'lm.iq_register'
     4 
     4 
     5 main.command ( 'register',
     5 main.command ( 'register',
     6 	function ( args )
     6 	function ( args )
       
     7 		local connection = main.connection ()
       
     8 		if not connection then
       
     9 			print "You are not online!"
       
    10 			return
       
    11 		end
     7 		local who
    12 		local who
     8 		if args and args ~= '' then
    13 		if args and args ~= '' then
     9 			who = args
    14 			who = args
    10 		else
    15 		else
    11 			who = main.full_jid ()
    16 			who = main.full_jid ()
    12 		end
    17 		end
    13 		iq_register.register ( lm.connection.bless ( main.connection () ), who,
    18 		iq_register.register ( lm.connection.bless ( connection ), who,
    14 			function ( form, submit, reject )
    19 			function ( form, submit, reject )
    15 				insert_form ( form,
    20 				insert_form ( form,
    16 					function ( form )
    21 					function ( form )
    17 						submit ( form,
    22 						submit ( form,
    18 							function ()
    23 							function ()
    36 				main.print_info ( who, 'Registration failed: ' .. mesg )
    41 				main.print_info ( who, 'Registration failed: ' .. mesg )
    37 			end )
    42 			end )
    38 	end, false, 'jid' )
    43 	end, false, 'jid' )
    39 main.command ( 'cancel',
    44 main.command ( 'cancel',
    40 	function ( args )
    45 	function ( args )
       
    46 		local connection = main.connection ()
       
    47 		if not connection then
       
    48 			print "You are not online!"
       
    49 			return
       
    50 		end
    41 		local who
    51 		local who
    42 		if args and args ~= '' then
    52 		if args and args ~= '' then
    43 			who = args
    53 			who = args
    44 		else
    54 		else
    45 			who = main.full_jid ()
    55 			who = main.full_jid ()
    46 		end
    56 		end
    47 		iq_register.unregister ( lm.connection.bless ( main.connection () ), who,
    57 		iq_register.unregister ( lm.connection.bless ( connection ), who,
    48 			function ( form, submit, reject )
    58 			function ( form, submit, reject )
    49 				if not form then
    59 				if not form then
    50 					main.print_info ( who, 'Successfully unregistered' )
    60 					main.print_info ( who, 'Successfully unregistered' )
    51 				else
    61 				else
    52 					insert_form ( form,
    62 					insert_form ( form,
    76 	end, false, 'jid' )
    86 	end, false, 'jid' )
    77 
    87 
    78 commands_help['register'] = "[jid]\n\nSends registration request to jid (or current buddy). You, probably, then will need to fill and send some form."
    88 commands_help['register'] = "[jid]\n\nSends registration request to jid (or current buddy). You, probably, then will need to fill and send some form."
    79 commands_help['cancel'] = "[jid]\n\nSends registration cancellation request to jid (or current buddy). May require a form filling."
    89 commands_help['cancel'] = "[jid]\n\nSends registration cancellation request to jid (or current buddy). May require a form filling."
    80 
    90 
    81 -- vim: se ts=4: --
    91 -- vim: se ts=4 sw=4: --