Software /
code /
verse
Changeset
235:3c93d6119477
plugins.register: Add in-band registration plugin
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 27 Nov 2011 21:56:21 +0000 |
parents | 234:a597da99810c |
children | 236:d75a209e57fc |
files | plugins/register.lua |
diffstat | 1 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/register.lua Sun Nov 27 21:56:21 2011 +0000 @@ -0,0 +1,27 @@ +local xmlns_register = "jabber:iq:register"; + +function verse.plugins.register(stream) + local function handle_features(features_stanza) + if features_stanza:get_child("register", "http://jabber.org/features/iq-register") then + stream:send_iq(verse.iq({ to = stream.host_, type = "set" }) + :tag("query", { xmlns = xmlns_register }) + :tag("username"):text(stream.username):up() + :tag("password"):text(stream.password):up() + , function (result) + if result.attr.type == "result" then + stream:event("registration-success"); + else + local type, condition, text = result:get_error(); + stream:debug("Registration failed: %s", condition); + stream:event("registration-failure", { type = type, condition = condition, text = text }); + end + end); + else + stream:debug("In-band registration not offered by server"); + stream:event("registration-failed", { condition = "service-unavailable" }); + end + stream:unhook("stream-features", handle_features); + return true; + end + stream:hook("stream-features", handle_features, 310); +end