Mercurial > prosody-modules
comparison mod_default_vcard/mod_default_vcard.lua @ 455:52f2188ec47d
mod_default_vcard: Sets initial vCard from data enterd on registration
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 15 Oct 2011 13:43:37 +0200 |
parents | |
children | 7236cdec3ea1 |
comparison
equal
deleted
inserted
replaced
454:3f101f7a26d0 | 455:52f2188ec47d |
---|---|
1 local datamanager = require "util.datamanager"; | |
2 local st = require "util.stanza"; | |
3 local host = module.host; | |
4 | |
5 module:hook("user-registered", function(event) | |
6 local username = event.username; | |
7 local data = datamanager.load(username, host, "account_details"); | |
8 local vcard = datamanager.load(username, host, "vcard"); | |
9 --module:log("debug", "Has account details: %s", data and "yes" or "no"); | |
10 --module:log("debug", "Has vCard: %s", vcard and "yes" or "no"); | |
11 if data and not vcard then | |
12 -- MAYBE | |
13 -- first .. " " .. last | |
14 -- first, last = name:match("^(%w+) (%w+)$") | |
15 local vcard = st.stanza("vCard", { xmlns = "vcard-temp" }) | |
16 :tag("VERSION"):text("3.0"):up() | |
17 :tag("N") | |
18 :tag("FAMILY"):text(data.last or ""):up() | |
19 :tag("GIVEN"):text(data.first or ""):up() | |
20 :up() | |
21 :tag("FN"):text(data.name or ""):up() | |
22 :tag("NICKNAME"):text(data.nick or username):up(); | |
23 local ok, err = datamanager.store(username, host, "vcard", st.preserialize(vcard)); | |
24 if not ok then | |
25 module:log("error", "Couldn't save vCard data, %s", err); | |
26 end | |
27 end | |
28 end); |