Comparison

mod_vjud/mod_vjud.lua @ 730:274bb1a96122

mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
author Kim Alvefur <zash@zash.se>
date Thu, 28 Jun 2012 05:24:26 +0200
parent 715:b1268d3aa6ce
child 732:317e142fe6f1
comparison
equal deleted inserted replaced
729:ce8e7b784be0 730:274bb1a96122
73 73
74 if stanza.attr.type == "get" then 74 if stanza.attr.type == "get" then
75 origin.send(st.reply(stanza):add_child(get_reply)); 75 origin.send(st.reply(stanza):add_child(get_reply));
76 else -- type == "set" 76 else -- type == "set"
77 local query = stanza.tags[1]; 77 local query = stanza.tags[1];
78 local first, last, nick, email =
79 (query:get_child_text"first" or false),
80 (query:get_child_text"last" or false),
81 (query:get_child_text"nick" or false),
82 (query:get_child_text"email" or false);
83
84 if not ( first or last or nick or email ) then
85 origin.send(st.error_reply(stanza, "modify", "not-acceptable", "All fields were empty"));
86 return true;
87 end
88
78 local reply = st.reply(stanza):query("jabber:iq:search"); 89 local reply = st.reply(stanza):query("jabber:iq:search");
79 local first, last, nick, email = 90
80 query:get_child_text"first",
81 query:get_child_text"last",
82 query:get_child_text"nick",
83 query:get_child_text"email";
84 first = first and #first and first;
85 last = last and #last and last;
86 nick = nick and #nick and nick;
87 email = email and #email and email;
88 local username, hostname = jid_split(email); 91 local username, hostname = jid_split(email);
89 if hostname == module.host and username and usermanager.user_exists(username, hostname) then 92 if hostname == module.host and username and usermanager.user_exists(username, hostname) then
90 local vCard = get_user_vcard(username); 93 local vCard = get_user_vcard(username);
91 if vCard then 94 if vCard then
92 reply:add_child(item_template.apply{ 95 reply:add_child(item_template.apply{
99 end 102 end
100 else 103 else
101 for username in pairs(opted_in) do 104 for username in pairs(opted_in) do
102 local vCard = get_user_vcard(username); 105 local vCard = get_user_vcard(username);
103 if vCard and ( 106 if vCard and (
104 (not first or (vCard.N and vCard.N[2] == first)) or 107 (vCard.N and vCard.N[2] == first) or
105 (not last or (vCard.N and vCard.N[1] == last)) or 108 (vCard.N and vCard.N[1] == last) or
106 (not nick or (vCard.NICKNAME and vCard.NICKNAME[1] == nick)) or 109 (vCard.NICKNAME and vCard.NICKNAME[1] == nick) or
107 (not email or (vCard.EMAIL and vCard.EMAIL[1] == email))) then 110 (vCard.EMAIL and vCard.EMAIL[1] == email)) then
108 reply:add_child(item_template.apply{ 111 reply:add_child(item_template.apply{
109 jid = username..at_host; 112 jid = username..at_host;
110 first = vCard.N and vCard.N[1] or nil; 113 first = vCard.N and vCard.N[1] or nil;
111 last = vCard.N and vCard.N[2] or nil; 114 last = vCard.N and vCard.N[2] or nil;
112 nick = vCard.NICKNAME and vCard.NICKNAME[1] or username; 115 nick = vCard.NICKNAME and vCard.NICKNAME[1] or username;