plugins/mod_invites.lua
changeset 13357 27512ebcc8af
parent 13213 c8d949cf6b09
child 13359 a6c8a50cdfb5
equal deleted inserted replaced
13356:b1f5a5531564 13357:27512ebcc8af
   200 	local invite = get(token);
   200 	local invite = get(token);
   201 	return invite and invite:use();
   201 	return invite and invite:use();
   202 end
   202 end
   203 
   203 
   204 --- shell command
   204 --- shell command
   205 do
   205 module:add_item("shell-command", {
   206 	-- Since the console is global this overwrites the command for
   206 	section = "invite";
   207 	-- each host it's loaded on, but this should be fine.
   207 	section_desc = "Create and manage invitations";
   208 
   208 	name = "create_account";
   209 	local get_module = require "prosody.core.modulemanager".get_module;
   209 	desc = "Create an invitation to make an account on this server with the specified JID (supply only a hostname to allow any username)";
   210 
   210 	args = { { name = "user_jid", type = "string" } };
   211 	local console_env = module:shared("/*/admin_shell/env");
   211 	host_selector = "user_jid";
   212 
   212 
   213 	-- luacheck: ignore 212/self
   213 	handler = function (self, user_jid)
   214 	console_env.invite = {};
       
   215 	function console_env.invite:create_account(user_jid)
       
   216 		local username, host = jid_split(user_jid);
   214 		local username, host = jid_split(user_jid);
   217 		local mod_invites, err = get_module(host, "invites");
   215 		local invite, err = create_account(username);
   218 		if not mod_invites then return nil, err or "mod_invites not loaded on this host"; end
       
   219 		local invite, err = mod_invites.create_account(username);
       
   220 		if not invite then return nil, err; end
   216 		if not invite then return nil, err; end
   221 		return true, invite.landing_page or invite.uri;
   217 		return true, invite.landing_page or invite.uri;
   222 	end
   218 	end;
   223 
   219 });
   224 	function console_env.invite:create_contact(user_jid, allow_registration)
   220 
       
   221 module:add_item("shell-command", {
       
   222 	section = "invite";
       
   223 	section_desc = "Create and manage invitations";
       
   224 	name = "create_contact";
       
   225 	desc = "Create an invitation to become contacts with the specified user";
       
   226 	args = { { name = "user_jid", type = "string" }, { name = "allow_registration" } };
       
   227 	host_selector = "user_jid";
       
   228 
       
   229 	handler = function (self, user_jid, allow_registration)
   225 		local username, host = jid_split(user_jid);
   230 		local username, host = jid_split(user_jid);
   226 		local mod_invites, err = get_module(host, "invites");
   231 		local invite, err = create_contact(username, allow_registration);
   227 		if not mod_invites then return nil, err or "mod_invites not loaded on this host"; end
       
   228 		local invite, err = mod_invites.create_contact(username, allow_registration);
       
   229 		if not invite then return nil, err; end
   232 		if not invite then return nil, err; end
   230 		return true, invite.landing_page or invite.uri;
   233 		return true, invite.landing_page or invite.uri;
   231 	end
   234 	end;
   232 end
   235 });
   233 
   236 
   234 local subcommands = {};
   237 local subcommands = {};
   235 
   238 
   236 --- prosodyctl command
   239 --- prosodyctl command
   237 function module.command(arg)
   240 function module.command(arg)