Changeset

13527:dba43269db5e

mod_invites_adhoc: Add password reset command To support cases where the admin does not have easy access to the command line to generate a password reset invite for someone who forgot their password.
author Kim Alvefur <zash@zash.se>
date Sun, 20 Oct 2024 12:11:21 +0200
parents 13526:3abed2ec7ab6
children 13529:3ec7222349ac
files CHANGES plugins/mod_invites_adhoc.lua
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES	Mon Oct 21 17:15:06 2024 +0200
+++ b/CHANGES	Sun Oct 20 12:11:21 2024 +0200
@@ -74,6 +74,7 @@
 - Support for Type=notify and notify-reload systemd service type added
 - Support for the roster *group* access_model in mod_pep
 - Support for systemd socket activation in server_epoll
+- mod_invites_adhoc gained a command for creating password resets
 
 ## Removed
 
--- a/plugins/mod_invites_adhoc.lua	Mon Oct 21 17:15:06 2024 +0200
+++ b/plugins/mod_invites_adhoc.lua	Sun Oct 20 12:11:21 2024 +0200
@@ -2,6 +2,7 @@
 local dataforms = require "prosody.util.dataforms";
 local datetime = require "prosody.util.datetime";
 local split_jid = require "prosody.util.jid".split;
+local adhocutil = require "prosody.util.adhoc";
 
 local new_adhoc = module:require("adhoc").new;
 
@@ -98,3 +99,32 @@
 				};
 			};
 		end, "admin"));
+
+local password_reset_form = dataforms.new({
+	title = "Generate Password Reset Invite";
+	{
+		name = "accountjid";
+		type = "jid-single";
+		required = true;
+		label = "The XMPP ID for the account to generate a password reset invite for";
+	};
+});
+
+module:provides("adhoc", new_adhoc("Create password reset invite", "xmpp:prosody.im/mod_invites_adhoc#password-reset",
+		adhocutil.new_simple_form(password_reset_form,
+		function (fields, err)
+			if err then return { status = "completed"; error = { message = "Fill in the form correctly" } }; end
+			local username = split_jid(fields.accountjid);
+			local invite = invites.create_account_reset(username);
+			return {
+				status = "completed";
+				result = {
+					layout = invite_result_form;
+					values = {
+						uri = invite.uri;
+						url = invite.landing_page;
+						expire = datetime.datetime(invite.expires);
+					};
+				};
+			};
+	end), "admin"));