| AnyEvent::XMPP::Ext::RegisterForm(3pm) | User Contributed Perl Documentation | AnyEvent::XMPP::Ext::RegisterForm(3pm) |
AnyEvent::XMPP::Ext::RegisterForm - Handle for in band registration
my $con = AnyEvent::XMPP::Connection->new (...);
...
$con->do_in_band_register (sub {
my ($form, $error) = @_;
if ($error) { print "ERROR: ".$error->string."\n" }
else {
if ($form->type eq 'simple') {
if ($form->has_field ('username') && $form->has_field ('password')) {
$form->set_field (
username => 'test',
password => 'qwerty',
);
$form->submit (sub {
my ($form, $error) = @_;
if ($error) { print "SUBMIT ERROR: ".$error->string."\n" }
else {
print "Successfully registered as ".$form->field ('username')."\n"
}
});
} else {
print "Couldn't fill out the form: " . $form->field ('instructions') ."\n";
}
} elsif ($form->type eq 'data_form' {
my $dform = $form->data_form;
... fill out the form $dform (of type AnyEvent::XMPP::DataForm) ...
$form->submit_data_form ($dform, sub {
my ($form, $error) = @_;
if ($error) { print "DATA FORM SUBMIT ERROR: ".$error->string."\n" }
else {
print "Successfully registered as ".$form->field ('username')."\n"
}
})
}
}
});
This module represents an in band registration form which can be filled out and submitted.
You can get an instance of this class only by requesting it from a AnyEvent::XMPP::Connection by calling the "request_inband_register_form" method.
If you have legacy form fields as a hash ref in $filled_legacy_form:
AnyEvent::XMPP::Ext::RegisterForm (
legacy_form => $filled_legacy_form,
answered => 1
);
If you have a data form in $answer_data_form:
AnyEvent::XMPP::Ext::RegisterForm (
legacy_form => $answer_data_form,
answered => 1
);
NOTE: This function is just a heuristic to fill out a form for automatic registration, but it might fail if the forms are more complex and have required fields that we don't know.
Registration without user interaction is theoretically not possible because forms can be different from server to server and require different information. Please also have a look at XEP-0077.
Note that if the form is more complicated this method will not work and it's not guranteed that the registration will be successful.
Calling this method on a answer form (where "is_answer_form" returns true) will have an undefined result.
If the form contained just nodes the keys will have undef as value.
If the form contained also register information, in case "is_already_registered" returns a true value, the values will contain the strings for the fields.
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>"
Copyright 2007, 2008 Robin Redeker, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 2022-12-06 | perl v5.36.0 |