Annotate

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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
715
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local dm_load = require "util.datamanager".load;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local dm_store = require "util.datamanager".store;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local usermanager = require "core.usermanager";
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local dataforms_new = require "util.dataforms".new;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local jid_split = require "util.jid".prepped_split;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local vcard = module:require "vcard";
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local st = require "util.stanza";
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 local template = require "util.template";
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local get_reply = template[[
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 <query xmlns="jabber:iq:search">
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 <instructions>Fill in one or more fields to search for any matching Jabber users.</instructions>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 <first/>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 <last/>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 <nick/>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 <email/>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 </query>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 ]].apply({});
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 local item_template = template[[
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 <item xmlns="jabber:iq:search" jid="{jid}">
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 <first>{first}</first>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 <last>{last}</last>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 <nick>{nick}</nick>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 <email>{email}</email>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 </item>
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 ]];
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 module:add_feature("jabber:iq:search");
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 local opted_in;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 function module.load()
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 opted_in = dm_load(nil, module.host, "user_index") or {};
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 function module.unload()
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 dm_store(nil, module.host, "user_index", opted_in);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 local opt_in_layout = dataforms_new{
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 title = "Search settings";
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 instructions = "Do you want to appear in search results?";
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 {
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 name = "searchable",
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 label = "Appear in search results?",
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 type = "boolean",
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 },
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 };
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 local vCard_mt = {
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 __index = function(t, k)
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 for i=1,#t do
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 if t[i].name == k then
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 t[k] = t[i];
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 return t[i]
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 };
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 local function get_user_vcard(user)
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 local vCard = dm_load(user, module.host, "vcard");
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 if vCard then
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 vCard = st.deserialize(vCard);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 vCard = vcard.xep54_to_lua(vCard);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 return setmetatable(vCard, vCard_mt);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 local at_host = "@"..module.host;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 module:hook("iq/host/jabber:iq:search:query", function(event)
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 local origin, stanza = event.origin, event.stanza;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 if stanza.attr.type == "get" then
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 origin.send(st.reply(stanza):add_child(get_reply));
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 else -- type == "set"
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 local query = stanza.tags[1];
730
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
78 local first, last, nick, email =
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
79 (query:get_child_text"first" or false),
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
80 (query:get_child_text"last" or false),
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
81 (query:get_child_text"nick" or false),
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
82 (query:get_child_text"email" or false);
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
83
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
84 if not ( first or last or nick or email ) then
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
85 origin.send(st.error_reply(stanza, "modify", "not-acceptable", "All fields were empty"));
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
86 return true;
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
87 end
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
88
715
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 local reply = st.reply(stanza):query("jabber:iq:search");
730
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
90
715
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 local username, hostname = jid_split(email);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 if hostname == module.host and username and usermanager.user_exists(username, hostname) then
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 local vCard = get_user_vcard(username);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 if vCard then
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 reply:add_child(item_template.apply{
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 jid = username..at_host;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 first = vCard.N and vCard.N[1] or nil;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 last = vCard.N and vCard.N[2] or nil;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 nick = vCard.NICKNAME and vCard.NICKNAME[1] or username;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 email = vCard.EMAIL and vCard.EMAIL[1] or nil;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 });
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 else
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 for username in pairs(opted_in) do
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 local vCard = get_user_vcard(username);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 if vCard and (
730
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
107 (vCard.N and vCard.N[2] == first) or
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
108 (vCard.N and vCard.N[1] == last) or
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
109 (vCard.NICKNAME and vCard.NICKNAME[1] == nick) or
274bb1a96122 mod_vjud: Missing fields should not match everyone. (Thanks Pidgin)
Kim Alvefur <zash@zash.se>
parents: 715
diff changeset
110 (vCard.EMAIL and vCard.EMAIL[1] == email)) then
715
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 reply:add_child(item_template.apply{
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 jid = username..at_host;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 first = vCard.N and vCard.N[1] or nil;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 last = vCard.N and vCard.N[2] or nil;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 nick = vCard.NICKNAME and vCard.NICKNAME[1] or username;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 email = vCard.EMAIL and vCard.EMAIL[1] or nil;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 });
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 origin.send(reply);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 return true;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 end);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 local function opt_in_handler(self, data, state)
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 local username, hostname = jid_split(data.from);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 if state then -- the second return value
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 if data.action == "cancel" then
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 return { status = "canceled" };
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 if not username or not hostname or hostname ~= module.host then
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 return { status = "error", error = { type = "cancel",
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 condition = "forbidden", message = "Invalid user or hostname." } };
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 local fields = opt_in_layout:data(data.form);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 opted_in[username] = fields.searchable or nil
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 return { status = "completed" }
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 else -- No state, send the form.
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 return { status = "executing", actions = { "complete" },
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 form = { layout = opt_in_layout, data = { searchable = opted_in[username] } } }, true;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 end
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 local adhoc_new = module:require "adhoc".new;
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 local adhoc_vjudsetup = adhoc_new("Search settings", "vjudsetup", opt_in_handler);--, "self");-- and nil);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 module:depends"adhoc";
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 module:provides("adhoc", adhoc_vjudsetup);
b1268d3aa6ce mod_vjud: Add. Thanks waqas for the base code.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152