Software /
code /
prosody
Annotate
plugins/mod_legacyauth.lua @ 414:405d414fbce2
Update TODO
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 25 Nov 2008 05:00:31 +0000 |
parent | 308:6345cf3e994a |
child | 421:63be85693710 |
rev | line source |
---|---|
30 | 1 |
2 local st = require "util.stanza"; | |
3 local t_concat = table.concat; | |
4 | |
5 add_iq_handler("c2s_unauthed", "jabber:iq:auth", | |
6 function (session, stanza) | |
7 local username = stanza.tags[1]:child_with_name("username"); | |
8 local password = stanza.tags[1]:child_with_name("password"); | |
9 local resource = stanza.tags[1]:child_with_name("resource"); | |
10 if not (username and password and resource) then | |
11 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
|
12 session.send(reply:query("jabber:iq:auth") |
30 | 13 :tag("username"):up() |
14 :tag("password"):up() | |
15 :tag("resource"):up()); | |
16 return true; | |
17 else | |
18 username, password, resource = t_concat(username), t_concat(password), t_concat(resource); | |
19 local reply = st.reply(stanza); | |
20 require "core.usermanager" | |
21 if usermanager.validate_credentials(session.host, username, password) then | |
22 -- Authentication successful! | |
38 | 23 local success, err = sessionmanager.make_authenticated(session, username); |
24 if success then | |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
25 local err_type, err_msg; |
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
26 success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); |
38 | 27 if not success then |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
28 session.send(st.error_reply(stanza, err_type, err, err_msg)); |
38 | 29 return true; |
30 end | |
30 | 31 end |
308
6345cf3e994a
Fixed mod_legacyauth to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
304
diff
changeset
|
32 session.send(st.reply(stanza)); |
30 | 33 return true; |
34 else | |
35 local reply = st.reply(stanza); | |
36 reply.attr.type = "error"; | |
37 reply:tag("error", { code = "401", type = "auth" }) | |
38 :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
|
39 session.send(reply); |
30 | 40 return true; |
41 end | |
42 end | |
43 | |
44 end); |