Software / code / prosody
Annotate
plugins/mod_legacyauth.lua @ 435:4087aa611de2
Log reason for connection failure
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 26 Nov 2008 23:47:23 +0000 |
| parent | 421:63be85693710 |
| child | 438:193f9dd64f17 |
| rev | line source |
|---|---|
| 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 |
| 30 | 7 add_iq_handler("c2s_unauthed", "jabber:iq:auth", |
| 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 | |
| 46 end); |