annotate mod_default_vcard/mod_default_vcard.lua @ 604:17e879822700

mod_c2s_auth_throttle: first commit
author Marco Cirillo <maranda@lightwitch.org>
date Thu, 09 Feb 2012 00:56:47 +0000
parents 52f2188ec47d
children 7236cdec3ea1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
455
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local datamanager = require "util.datamanager";
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local st = require "util.stanza";
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local host = module.host;
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 module:hook("user-registered", function(event)
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local username = event.username;
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local data = datamanager.load(username, host, "account_details");
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local vcard = datamanager.load(username, host, "vcard");
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 --module:log("debug", "Has account details: %s", data and "yes" or "no");
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 --module:log("debug", "Has vCard: %s", vcard and "yes" or "no");
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 if data and not vcard then
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 -- MAYBE
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 -- first .. " " .. last
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 -- first, last = name:match("^(%w+) (%w+)$")
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local vcard = st.stanza("vCard", { xmlns = "vcard-temp" })
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 :tag("VERSION"):text("3.0"):up()
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 :tag("N")
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 :tag("FAMILY"):text(data.last or ""):up()
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 :tag("GIVEN"):text(data.first or ""):up()
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 :up()
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 :tag("FN"):text(data.name or ""):up()
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 :tag("NICKNAME"):text(data.nick or username):up();
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 local ok, err = datamanager.store(username, host, "vcard", st.preserialize(vcard));
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 if not ok then
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 module:log("error", "Couldn't save vCard data, %s", err);
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
52f2188ec47d mod_default_vcard: Sets initial vCard from data enterd on registration
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end);