Software /
code /
prosody
Annotate
plugins/mod_legacyauth.lua @ 758:b1885732e979
GPL->MIT!
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 30 Jan 2009 17:22:56 +0000 |
parent | 615:4ae3e81513f3 |
child | 759:5cccfb5da6cb |
rev | line source |
---|---|
615 | 1 -- Prosody IM v0.2 |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
2 -- Copyright (C) 2008 Matthew Wild |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
3 -- Copyright (C) 2008 Waqas Hussain |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
8 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 |
30 | 10 |
11 local st = require "util.stanza"; | |
12 local t_concat = table.concat; | |
13 | |
541
3521e0851c9e
Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
14 module:add_feature("jabber:iq:auth"); |
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
308
diff
changeset
|
15 |
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
|
16 module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", |
30 | 17 function (session, stanza) |
18 local username = stanza.tags[1]:child_with_name("username"); | |
19 local password = stanza.tags[1]:child_with_name("password"); | |
20 local resource = stanza.tags[1]:child_with_name("resource"); | |
21 if not (username and password and resource) then | |
22 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
|
23 session.send(reply:query("jabber:iq:auth") |
30 | 24 :tag("username"):up() |
25 :tag("password"):up() | |
26 :tag("resource"):up()); | |
27 return true; | |
28 else | |
29 username, password, resource = t_concat(username), t_concat(password), t_concat(resource); | |
30 local reply = st.reply(stanza); | |
31 require "core.usermanager" | |
32 if usermanager.validate_credentials(session.host, username, password) then | |
33 -- Authentication successful! | |
38 | 34 local success, err = sessionmanager.make_authenticated(session, username); |
35 if success then | |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
36 local err_type, err_msg; |
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
37 success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); |
38 | 38 if not success then |
304
7b28fa8bbfe5
Code cleanup for resource binding
Waqas Hussain <waqas20@gmail.com>
parents:
154
diff
changeset
|
39 session.send(st.error_reply(stanza, err_type, err, err_msg)); |
38 | 40 return true; |
41 end | |
30 | 42 end |
308
6345cf3e994a
Fixed mod_legacyauth to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
304
diff
changeset
|
43 session.send(st.reply(stanza)); |
30 | 44 return true; |
45 else | |
46 local reply = st.reply(stanza); | |
47 reply.attr.type = "error"; | |
48 reply:tag("error", { code = "401", type = "auth" }) | |
49 :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
|
50 session.send(reply); |
30 | 51 return true; |
52 end | |
53 end | |
54 | |
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
|
55 end); |