Software / code / prosody
Annotate
plugins/mod_register.lua @ 7041:aff786e7b4ce
net.server_select: Close all connections when quitting (and not just stepping), matches server_event
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 02 Jan 2016 20:42:20 +0000 |
| parent | 7037:5d52e4ee2ae1 |
| child | 7293:c4af754d1e1b |
| rev | line source |
|---|---|
|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1189
diff
changeset
|
1 -- Prosody IM |
|
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2448
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
|
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2448
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5763
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 |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local st = require "util.stanza"; |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
11 local dataform_new = require "util.dataforms".new; |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local usermanager_user_exists = require "core.usermanager".user_exists; |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 local usermanager_create_user = require "core.usermanager".create_user; |
|
2935
4e4d0d899d9d
mod_register: Use set_password to set passwords instead of create_user.
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
14 local usermanager_set_password = require "core.usermanager".set_password; |
|
3996
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
15 local usermanager_delete_user = require "core.usermanager".delete_user; |
|
927
cc180d25dbeb
Fixed: mod_register: Node prepping was not being applied to usernames (part of issue #57)
Waqas Hussain <waqas20@gmail.com>
parents:
926
diff
changeset
|
16 local nodeprep = require "util.encodings".stringprep.nodeprep; |
|
3995
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
17 local jid_bare = require "util.jid".bare; |
|
7025
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
18 local create_throttle = require "util.throttle".create; |
|
7026
f0dc5cc11d0e
mod_register: Use util.cache to limit the number of per-ip throttles kept
Kim Alvefur <zash@zash.se>
parents:
7025
diff
changeset
|
19 local new_cache = require "util.cache".new; |
|
3995
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
20 |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
21 local compat = module:get_option_boolean("registration_compat", true); |
|
4270
d2d47fde9811
mod_register: Change the default for 'allow_registration' from true to false, most users shouldn't be affected as allow_registration is already explicitly set in the default config file.
Matthew Wild <mwild1@gmail.com>
parents:
4269
diff
changeset
|
22 local allow_registration = module:get_option_boolean("allow_registration", false); |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
23 local additional_fields = module:get_option("additional_registration_fields", {}); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
24 |
|
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5371
diff
changeset
|
25 local account_details = module:open_store("account_details"); |
|
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5371
diff
changeset
|
26 |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
27 local field_map = { |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
28 username = { name = "username", type = "text-single", label = "Username", required = true }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
29 password = { name = "password", type = "text-private", label = "Password", required = true }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
30 nick = { name = "nick", type = "text-single", label = "Nickname" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
31 name = { name = "name", type = "text-single", label = "Full Name" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
32 first = { name = "first", type = "text-single", label = "Given Name" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
33 last = { name = "last", type = "text-single", label = "Family Name" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
34 email = { name = "email", type = "text-single", label = "Email" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
35 address = { name = "address", type = "text-single", label = "Street" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
36 city = { name = "city", type = "text-single", label = "City" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
37 state = { name = "state", type = "text-single", label = "State" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
38 zip = { name = "zip", type = "text-single", label = "Postal code" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
39 phone = { name = "phone", type = "text-single", label = "Telephone number" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
40 url = { name = "url", type = "text-single", label = "Webpage" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
41 date = { name = "date", type = "text-single", label = "Birth date" }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
42 }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
43 |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
44 local registration_form = dataform_new{ |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
45 title = "Creating a new account"; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
46 instructions = "Choose a username and password for use with this service."; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
47 |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
48 field_map.username; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
49 field_map.password; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
50 }; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
51 |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
52 local registration_query = st.stanza("query", {xmlns = "jabber:iq:register"}) |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
53 :tag("instructions"):text("Choose a username and password for use with this service."):up() |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
54 :tag("username"):up() |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
55 :tag("password"):up(); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
56 |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
57 for _, field in ipairs(additional_fields) do |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
58 if type(field) == "table" then |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
59 registration_form[#registration_form + 1] = field; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
60 else |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
61 if field:match("%+$") then |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
62 field = field:sub(1, #field - 1); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
63 field_map[field].required = true; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
64 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
65 |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
66 registration_form[#registration_form + 1] = field_map[field]; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
67 registration_query:tag(field):up(); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
68 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
69 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
70 registration_query:add_child(registration_form:form()); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 |
|
541
3521e0851c9e
Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
72 module:add_feature("jabber:iq:register"); |
|
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
386
diff
changeset
|
73 |
|
4268
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
74 local register_stream_feature = st.stanza("register", {xmlns="http://jabber.org/features/iq-register"}):up(); |
|
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
75 module:hook("stream-features", function(event) |
| 5707 | 76 local session, features = event.origin, event.features; |
|
4268
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
77 |
|
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
78 -- Advertise registration to unauthorized clients only. |
|
4269
cd4011af8b4c
mod_register: Move allow_registration option into an upvalue for efficiency (now it is being checked on every new c2s stream)
Matthew Wild <mwild1@gmail.com>
parents:
4268
diff
changeset
|
79 if not(allow_registration) or session.type ~= "c2s_unauthed" then |
|
4268
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
80 return |
|
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
81 end |
|
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
82 |
|
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
83 features:add_child(register_stream_feature); |
|
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
84 end); |
|
c249f10eb9bb
Advertise in-band registration support.
Glenn Maynard <glenn@zewt.org>
parents:
3997
diff
changeset
|
85 |
|
3995
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
86 local function handle_registration_stanza(event) |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
87 local session, stanza = event.origin, event.stanza; |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
88 local log = session.log or module._log; |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
89 |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
90 local query = stanza.tags[1]; |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
91 if stanza.attr.type == "get" then |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
92 local reply = st.reply(stanza); |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
93 reply:tag("query", {xmlns = "jabber:iq:register"}) |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
94 :tag("registered"):up() |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
95 :tag("username"):text(session.username):up() |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
96 :tag("password"):up(); |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
97 session.send(reply); |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
98 else -- stanza.attr.type == "set" |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
99 if query.tags[1] and query.tags[1].name == "remove" then |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
100 local username, host = session.username, session.host; |
|
5098
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
101 |
|
7018
5c3d4254d415
mod_register: Add comment explaining the workaround for replying when the account is being deleted
Kim Alvefur <zash@zash.se>
parents:
7017
diff
changeset
|
102 -- This one weird trick sends a reply to this stanza before the user is deleted |
|
5098
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
103 local old_session_close = session.close; |
|
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
104 session.close = function(session, ...) |
|
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
105 session.send(st.reply(stanza)); |
|
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
106 return old_session_close(session, ...); |
|
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
107 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5763
diff
changeset
|
108 |
|
3996
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
109 local ok, err = usermanager_delete_user(username, host); |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5763
diff
changeset
|
110 |
|
3996
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
111 if not ok then |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
112 log("debug", "Removing user account %s@%s failed: %s", username, host, err); |
|
5098
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
113 session.close = old_session_close; |
|
3996
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
114 session.send(st.error_reply(stanza, "cancel", "service-unavailable", err)); |
|
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
115 return true; |
|
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
116 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5763
diff
changeset
|
117 |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
118 log("info", "User removed their account: %s@%s", username, host); |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
119 module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session }); |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
120 else |
|
5637
991b47778bf3
mod_register: get_child_text()!
Kim Alvefur <zash@zash.se>
parents:
5500
diff
changeset
|
121 local username = nodeprep(query:get_child_text("username")); |
|
991b47778bf3
mod_register: get_child_text()!
Kim Alvefur <zash@zash.se>
parents:
5500
diff
changeset
|
122 local password = query:get_child_text("password"); |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
123 if username and password then |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
124 if username == session.username then |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
125 if usermanager_set_password(username, password, session.host) then |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
126 session.send(st.reply(stanza)); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
127 else |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
128 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
129 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 end |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 else |
|
311
513bd52e8e19
Fixed mod_register to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
85
diff
changeset
|
132 session.send(st.error_reply(stanza, "modify", "bad-request")); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 end |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
134 else |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
135 session.send(st.error_reply(stanza, "modify", "bad-request")); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 end |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 end |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
138 end |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
139 return true; |
|
3995
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
140 end |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
141 |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
142 module:hook("iq/self/jabber:iq:register:query", handle_registration_stanza); |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
143 if compat then |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
144 module:hook("iq/host/jabber:iq:register:query", function (event) |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
145 local session, stanza = event.origin, event.stanza; |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
146 if session.type == "c2s" and jid_bare(stanza.attr.to) == session.host then |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
147 return handle_registration_stanza(event); |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
148 end |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
149 end); |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
150 end |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
151 |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
152 local function parse_response(query) |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
153 local form = query:get_child("x", "jabber:x:data"); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
154 if form then |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
155 return registration_form:data(form); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
156 else |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
157 local data = {}; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
158 local errors = {}; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
159 for _, field in ipairs(registration_form) do |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
160 local name, required = field.name, field.required; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
161 if field_map[name] then |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
162 data[name] = query:get_child_text(name); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
163 if (not data[name] or #data[name] == 0) and required then |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
164 errors[name] = "Required value missing"; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
165 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
166 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
167 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
168 if next(errors) then |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
169 return data, errors; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
170 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
171 return data; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
172 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
173 end |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
174 |
|
5763
0e52f1d5ca71
mod_register: Use more specific get_option variants
Kim Alvefur <zash@zash.se>
parents:
5707
diff
changeset
|
175 local min_seconds_between_registrations = module:get_option_number("min_seconds_between_registrations"); |
|
0e52f1d5ca71
mod_register: Use more specific get_option variants
Kim Alvefur <zash@zash.se>
parents:
5707
diff
changeset
|
176 local whitelist_only = module:get_option_boolean("whitelist_registration_only"); |
|
0e52f1d5ca71
mod_register: Use more specific get_option variants
Kim Alvefur <zash@zash.se>
parents:
5707
diff
changeset
|
177 local whitelisted_ips = module:get_option_set("registration_whitelist", { "127.0.0.1" })._items; |
|
0e52f1d5ca71
mod_register: Use more specific get_option variants
Kim Alvefur <zash@zash.se>
parents:
5707
diff
changeset
|
178 local blacklisted_ips = module:get_option_set("registration_blacklist", {})._items; |
|
690
e901a0709005
Added rate limiting to in-band registration, and added IP [black/white]lists
Matthew Wild <mwild1@gmail.com>
parents:
665
diff
changeset
|
179 |
|
7025
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
180 local throttle_max = module:get_option_number("registration_throttle_max", min_seconds_between_registrations and 1); |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
181 local throttle_period = module:get_option_number("registration_throttle_period", min_seconds_between_registrations); |
|
7026
f0dc5cc11d0e
mod_register: Use util.cache to limit the number of per-ip throttles kept
Kim Alvefur <zash@zash.se>
parents:
7025
diff
changeset
|
182 local throttle_cache_size = module:get_option_number("registration_throttle_cache_size", 100); |
| 7037 | 183 local blacklist_overflow = module:get_option_boolean("blacklist_on_registration_throttle_overload", false); |
|
7026
f0dc5cc11d0e
mod_register: Use util.cache to limit the number of per-ip throttles kept
Kim Alvefur <zash@zash.se>
parents:
7025
diff
changeset
|
184 |
|
7027
77d838ba91c6
mod_register: Support for blacklisting ips that are still over limit when they get pushed out of the cache
Kim Alvefur <zash@zash.se>
parents:
7026
diff
changeset
|
185 local throttle_cache = new_cache(throttle_cache_size, blacklist_overflow and function (ip, throttle) |
|
77d838ba91c6
mod_register: Support for blacklisting ips that are still over limit when they get pushed out of the cache
Kim Alvefur <zash@zash.se>
parents:
7026
diff
changeset
|
186 if not throttle:peek() then |
|
77d838ba91c6
mod_register: Support for blacklisting ips that are still over limit when they get pushed out of the cache
Kim Alvefur <zash@zash.se>
parents:
7026
diff
changeset
|
187 module:log("info", "Adding ip %s to registration blacklist", ip); |
|
77d838ba91c6
mod_register: Support for blacklisting ips that are still over limit when they get pushed out of the cache
Kim Alvefur <zash@zash.se>
parents:
7026
diff
changeset
|
188 blacklisted_ips[ip] = true; |
|
77d838ba91c6
mod_register: Support for blacklisting ips that are still over limit when they get pushed out of the cache
Kim Alvefur <zash@zash.se>
parents:
7026
diff
changeset
|
189 end |
|
77d838ba91c6
mod_register: Support for blacklisting ips that are still over limit when they get pushed out of the cache
Kim Alvefur <zash@zash.se>
parents:
7026
diff
changeset
|
190 end); |
|
7025
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
191 |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
192 local function check_throttle(ip) |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
193 if not throttle_max then return true end |
|
7026
f0dc5cc11d0e
mod_register: Use util.cache to limit the number of per-ip throttles kept
Kim Alvefur <zash@zash.se>
parents:
7025
diff
changeset
|
194 local throttle = throttle_cache:get(ip); |
|
7025
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
195 if not throttle then |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
196 throttle = create_throttle(throttle_max, throttle_period); |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
197 end |
|
7026
f0dc5cc11d0e
mod_register: Use util.cache to limit the number of per-ip throttles kept
Kim Alvefur <zash@zash.se>
parents:
7025
diff
changeset
|
198 throttle_cache:set(ip, throttle); |
|
7025
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
199 return throttle:poll(1); |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
200 end |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
201 |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
202 module:hook("stanza/iq/jabber:iq:register:query", function(event) |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
203 local session, stanza = event.origin, event.stanza; |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
204 local log = session.log or module._log; |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
205 |
|
4269
cd4011af8b4c
mod_register: Move allow_registration option into an upvalue for efficiency (now it is being checked on every new c2s stream)
Matthew Wild <mwild1@gmail.com>
parents:
4268
diff
changeset
|
206 if not(allow_registration) or session.type ~= "c2s_unauthed" then |
|
665
09e0e9c722a3
Add allow_registration option to disable account registration
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
207 session.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
208 else |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
209 local query = stanza.tags[1]; |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
210 if stanza.attr.type == "get" then |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
211 local reply = st.reply(stanza); |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
212 reply:add_child(registration_query); |
|
311
513bd52e8e19
Fixed mod_register to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
85
diff
changeset
|
213 session.send(reply); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
214 elseif stanza.attr.type == "set" then |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
215 if query.tags[1] and query.tags[1].name == "remove" then |
|
311
513bd52e8e19
Fixed mod_register to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
85
diff
changeset
|
216 session.send(st.error_reply(stanza, "auth", "registration-required")); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
217 else |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
218 local data, errors = parse_response(query); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
219 if errors then |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
220 session.send(st.error_reply(stanza, "modify", "not-acceptable")); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
221 else |
|
690
e901a0709005
Added rate limiting to in-band registration, and added IP [black/white]lists
Matthew Wild <mwild1@gmail.com>
parents:
665
diff
changeset
|
222 -- Check that the user is not blacklisted or registering too often |
|
2085
64872e216e23
mod_register: Log a debug message when a session's IP is not available.
Waqas Hussain <waqas20@gmail.com>
parents:
1861
diff
changeset
|
223 if not session.ip then |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
224 log("debug", "User's IP not known; can't apply blacklist/whitelist"); |
|
2085
64872e216e23
mod_register: Log a debug message when a session's IP is not available.
Waqas Hussain <waqas20@gmail.com>
parents:
1861
diff
changeset
|
225 elseif blacklisted_ips[session.ip] or (whitelist_only and not whitelisted_ips[session.ip]) then |
|
1859
c965b0accc7c
mod_register: Added helpful text to registration error responses.
Waqas Hussain <waqas20@gmail.com>
parents:
1858
diff
changeset
|
226 session.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not allowed to register an account.")); |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
227 return true; |
|
690
e901a0709005
Added rate limiting to in-band registration, and added IP [black/white]lists
Matthew Wild <mwild1@gmail.com>
parents:
665
diff
changeset
|
228 elseif min_seconds_between_registrations and not whitelisted_ips[session.ip] then |
|
7025
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
229 if check_throttle(session.ip) then |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
230 session.send(st.error_reply(stanza, "wait", "not-acceptable")); |
|
236e8d1ee96c
mod_register: Switch to using util.throttle for limiting registrations per ip per time
Kim Alvefur <zash@zash.se>
parents:
7018
diff
changeset
|
231 return true; |
|
690
e901a0709005
Added rate limiting to in-band registration, and added IP [black/white]lists
Matthew Wild <mwild1@gmail.com>
parents:
665
diff
changeset
|
232 end |
|
e901a0709005
Added rate limiting to in-band registration, and added IP [black/white]lists
Matthew Wild <mwild1@gmail.com>
parents:
665
diff
changeset
|
233 end |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
234 local username, password = nodeprep(data.username), data.password; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
235 data.username, data.password = nil, nil; |
|
1857
ef266aa8e18f
mod_register: Fixed: No error was returned if username failed nodeprep.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
236 local host = module.host; |
|
2448
542335c8a5bc
mod_register: Return a <not-acceptable/> error on empty usernames (thanks Neustradamus).
Waqas Hussain <waqas20@gmail.com>
parents:
2260
diff
changeset
|
237 if not username or username == "" then |
|
1859
c965b0accc7c
mod_register: Added helpful text to registration error responses.
Waqas Hussain <waqas20@gmail.com>
parents:
1858
diff
changeset
|
238 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid.")); |
|
5165
39bb9344f194
mod_register: Fire event to allow blocking user registration
Florian Zeitz <florob@babelmonkeys.de>
parents:
5098
diff
changeset
|
239 return true; |
|
39bb9344f194
mod_register: Fire event to allow blocking user registration
Florian Zeitz <florob@babelmonkeys.de>
parents:
5098
diff
changeset
|
240 end |
|
39bb9344f194
mod_register: Fire event to allow blocking user registration
Florian Zeitz <florob@babelmonkeys.de>
parents:
5098
diff
changeset
|
241 local user = { username = username , host = host, allowed = true } |
|
39bb9344f194
mod_register: Fire event to allow blocking user registration
Florian Zeitz <florob@babelmonkeys.de>
parents:
5098
diff
changeset
|
242 module:fire_event("user-registering", user); |
|
39bb9344f194
mod_register: Fire event to allow blocking user registration
Florian Zeitz <florob@babelmonkeys.de>
parents:
5098
diff
changeset
|
243 if not user.allowed then |
|
39bb9344f194
mod_register: Fire event to allow blocking user registration
Florian Zeitz <florob@babelmonkeys.de>
parents:
5098
diff
changeset
|
244 session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is forbidden.")); |
|
1857
ef266aa8e18f
mod_register: Fixed: No error was returned if username failed nodeprep.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
245 elseif usermanager_user_exists(username, host) then |
|
1859
c965b0accc7c
mod_register: Added helpful text to registration error responses.
Waqas Hussain <waqas20@gmail.com>
parents:
1858
diff
changeset
|
246 session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
247 else |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
248 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
249 local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk."); |
|
1857
ef266aa8e18f
mod_register: Fixed: No error was returned if username failed nodeprep.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
250 if usermanager_create_user(username, password, host) then |
|
5500
eeea0eb2602a
mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
Kim Alvefur <zash@zash.se>
parents:
5371
diff
changeset
|
251 if next(data) and not account_details:set(username, data) then |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
252 usermanager_delete_user(username, host); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
253 session.send(error_reply); |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
254 return true; |
|
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
255 end |
|
311
513bd52e8e19
Fixed mod_register to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
85
diff
changeset
|
256 session.send(st.reply(stanza)); -- user created! |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
257 log("info", "User account created: %s@%s", username, host); |
|
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3529
diff
changeset
|
258 module:fire_event("user-registered", { |
|
1857
ef266aa8e18f
mod_register: Fixed: No error was returned if username failed nodeprep.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
259 username = username, host = host, source = "mod_register", |
|
1189
63ed3902f357
mod_register: Attach session to user-registered and user-deregistered events
Matthew Wild <mwild1@gmail.com>
parents:
1184
diff
changeset
|
260 session = session }); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
261 else |
|
4398
acc37e221940
mod_register: Add support for additional registration fields
Florian Zeitz <florob@babelmonkeys.de>
parents:
4270
diff
changeset
|
262 session.send(error_reply); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
263 end |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
264 end |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
265 end |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
266 end |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
267 end |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
268 end |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
269 return true; |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
270 end); |