Sat, 29 Nov 2008 19:52:20 +0000
Make ejabberd2prosody.lua a little more cross-platform :)
30 | 1 | |
2 | local st = require "util.stanza"; | |
3 | local t_concat = table.concat; | |
4 | ||
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
308
diff
changeset
|
5 | require "core.discomanager".set("legacyauth", "jabber:iq:auth"); |
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
308
diff
changeset
|
6 | |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
421
diff
changeset
|
7 | module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", |
30 | 8 | function (session, stanza) |
9 | local username = stanza.tags[1]:child_with_name("username"); | |
10 | local password = stanza.tags[1]:child_with_name("password"); | |
11 | local resource = stanza.tags[1]:child_with_name("resource"); | |
12 | if not (username and password and resource) then | |
13 | local reply = st.reply(stanza); | |
308
6345cf3e994a
Fixed mod_legacyauth to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
304
diff
changeset
|
14 | session.send(reply:query("jabber:iq:auth") |
30 | 15 | :tag("username"):up() |
16 | :tag("password"):up() | |
17 | :tag("resource"):up()); | |
18 | return true; | |
19 | else | |
20 | username, password, resource = t_concat(username), t_concat(password), t_concat(resource); | |
21 | local reply = st.reply(stanza); | |
22 | require "core.usermanager" | |
23 | if usermanager.validate_credentials(session.host, username, password) then | |
24 | -- Authentication successful! | |
38 | 25 | local success, err = sessionmanager.make_authenticated(session, username); |
26 | if success then | |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
27 | local err_type, err_msg; |
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
28 | success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); |
38 | 29 | if not success then |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
30 | session.send(st.error_reply(stanza, err_type, err, err_msg)); |
38 | 31 | return true; |
32 | end | |
30 | 33 | end |
308
6345cf3e994a
Fixed mod_legacyauth to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
304
diff
changeset
|
34 | session.send(st.reply(stanza)); |
30 | 35 | return true; |
36 | else | |
37 | local reply = st.reply(stanza); | |
38 | reply.attr.type = "error"; | |
39 | reply:tag("error", { code = "401", type = "auth" }) | |
40 | :tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); | |
308
6345cf3e994a
Fixed mod_legacyauth to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
304
diff
changeset
|
41 | session.send(reply); |
30 | 42 | return true; |
43 | end | |
44 | end | |
45 | ||
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
421
diff
changeset
|
46 | end); |