author | Waqas Hussain <waqas20@gmail.com> |
Sun, 16 Nov 2008 03:16:53 +0500 | |
changeset 304 | 7b28fa8bbfe5 |
parent 154 | 1fee9396ca2f |
child 308 | 6345cf3e994a |
permissions | -rw-r--r-- |
30 | 1 |
|
2 |
local st = require "util.stanza"; |
|
3 |
local send = require "core.sessionmanager".send_to_session; |
|
4 |
local t_concat = table.concat; |
|
5 |
||
6 |
add_iq_handler("c2s_unauthed", "jabber:iq:auth", |
|
7 |
function (session, stanza) |
|
8 |
local username = stanza.tags[1]:child_with_name("username"); |
|
9 |
local password = stanza.tags[1]:child_with_name("password"); |
|
10 |
local resource = stanza.tags[1]:child_with_name("resource"); |
|
11 |
if not (username and password and resource) then |
|
12 |
local reply = st.reply(stanza); |
|
13 |
send(session, reply:query("jabber:iq:auth") |
|
14 |
:tag("username"):up() |
|
15 |
:tag("password"):up() |
|
16 |
:tag("resource"):up()); |
|
17 |
return true; |
|
18 |
else |
|
19 |
username, password, resource = t_concat(username), t_concat(password), t_concat(resource); |
|
20 |
local reply = st.reply(stanza); |
|
21 |
require "core.usermanager" |
|
22 |
if usermanager.validate_credentials(session.host, username, password) then |
|
23 |
-- Authentication successful! |
|
38 | 24 |
local success, err = sessionmanager.make_authenticated(session, username); |
25 |
if success then |
|
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
26 |
local err_type, err_msg; |
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
27 |
success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); |
38 | 28 |
if not success then |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
29 |
session.send(st.error_reply(stanza, err_type, err, err_msg)); |
38 | 30 |
return true; |
31 |
end |
|
30 | 32 |
end |
33 |
send(session, st.reply(stanza)); |
|
34 |
return true; |
|
35 |
else |
|
36 |
local reply = st.reply(stanza); |
|
37 |
reply.attr.type = "error"; |
|
38 |
reply:tag("error", { code = "401", type = "auth" }) |
|
39 |
:tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); |
|
154
1fee9396ca2f
Fix mod_legacyauth to not use old stanza_dispatch
Matthew Wild <mwild1@gmail.com>
parents:
45
diff
changeset
|
40 |
send(session, reply); |
30 | 41 |
return true; |
42 |
end |
|
43 |
end |
|
44 |
||
45 |
end); |