Mercurial > prosody-modules
comparison mod_easy_invite/mod_easy_invite.lua @ 4023:7e2db4d61f6c
mod_easy_invite: backport: ensure session exists before accessing it
Backport from https://github.com/snikket-im/snikket-server
This prevents a 500 issue when using mod_register_web.
| author | Maxime “pep” Buquet <pep@bouah.net> |
|---|---|
| date | Sun, 17 May 2020 22:38:55 +0200 |
| parents | 3ac31ddab7eb |
| children | 6cdbca89b8be |
comparison
equal
deleted
inserted
replaced
| 4022:3ac31ddab7eb | 4023:7e2db4d61f6c |
|---|---|
| 135 return true; | 135 return true; |
| 136 end); | 136 end); |
| 137 | 137 |
| 138 -- Registration attempt - ensure a valid preauth token has been supplied | 138 -- Registration attempt - ensure a valid preauth token has been supplied |
| 139 module:hook("user-registering", function (event) | 139 module:hook("user-registering", function (event) |
| 140 local validated_invite = event.session.validated_invite; | 140 local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); |
| 141 if invite_only and not validated_invite then | 141 if invite_only and not validated_invite then |
| 142 event.allowed = false; | 142 event.allowed = false; |
| 143 event.reason = "Registration on this server is through invitation only"; | 143 event.reason = "Registration on this server is through invitation only"; |
| 144 return; | 144 return; |
| 145 end | 145 end |
| 167 subscribe(host, user2, user1); | 167 subscribe(host, user2, user1); |
| 168 end | 168 end |
| 169 | 169 |
| 170 -- Registration successful, if there was a preauth token, mark it as used | 170 -- Registration successful, if there was a preauth token, mark it as used |
| 171 module:hook("user-registered", function (event) | 171 module:hook("user-registered", function (event) |
| 172 local validated_invite = event.session.validated_invite; | 172 local validated_invite = event.validated_invite or (event.session and event.session.validated_invite); |
| 173 if not validated_invite then | 173 if not validated_invite then |
| 174 return; | 174 return; |
| 175 end | 175 end |
| 176 local inviter_username = validated_invite.inviter; | 176 local inviter_username = validated_invite.inviter; |
| 177 validated_invite:use(); | 177 validated_invite:use(); |
