Mercurial > prosody-modules
comparison mod_lastlog/mod_lastlog.lua @ 1493:d5e8758d391d
mod_lastlog: Fix traceback if no session included with event (eg from mod_register_web) (thanks biszkopcik)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 25 Aug 2014 00:38:14 +0200 |
| parents | 7dbde05b48a9 |
| children |
comparison
equal
deleted
inserted
replaced
| 1492:8c4a2d85e8bf | 1493:d5e8758d391d |
|---|---|
| 8 local session = event.session; | 8 local session = event.session; |
| 9 if session.username then | 9 if session.username then |
| 10 datamanager.store(session.username, host, "lastlog", { | 10 datamanager.store(session.username, host, "lastlog", { |
| 11 event = "login"; | 11 event = "login"; |
| 12 timestamp = time(), | 12 timestamp = time(), |
| 13 ip = log_ip and session.ip or nil, | 13 ip = log_ip and session and session.ip or nil, |
| 14 }); | 14 }); |
| 15 end | 15 end |
| 16 end); | 16 end); |
| 17 | 17 |
| 18 module:hook("resource-unbind", function(event) | 18 module:hook("resource-unbind", function(event) |
| 19 local session = event.session; | 19 local session = event.session; |
| 20 if session.username then | 20 if session.username then |
| 21 datamanager.store(session.username, host, "lastlog", { | 21 datamanager.store(session.username, host, "lastlog", { |
| 22 event = "logout"; | 22 event = "logout"; |
| 23 timestamp = time(), | 23 timestamp = time(), |
| 24 ip = log_ip and session.ip or nil, | 24 ip = log_ip and session and session.ip or nil, |
| 25 }); | 25 }); |
| 26 end | 26 end |
| 27 end); | 27 end); |
| 28 | 28 |
| 29 module:hook("user-registered", function(event) | 29 module:hook("user-registered", function(event) |
| 30 local session = event.session; | 30 local session = event.session; |
| 31 datamanager.store(event.username, host, "lastlog", { | 31 datamanager.store(event.username, host, "lastlog", { |
| 32 event = "registered"; | 32 event = "registered"; |
| 33 timestamp = time(), | 33 timestamp = time(), |
| 34 ip = log_ip and session.ip or nil, | 34 ip = log_ip and session and session.ip or nil, |
| 35 }); | 35 }); |
| 36 end); | 36 end); |
| 37 | 37 |
| 38 | 38 |
| 39 if module:get_host_type() == "component" then | 39 if module:get_host_type() == "component" then |
