diff mod_invites_register_web/mod_invites_register_web.lua @ 4833:15cf32e666da

mod_invites_register_web: Add mod_password_policy checks for web registration
author Matthew Wild <mwild1@gmail.com>
date Wed, 22 Dec 2021 15:05:31 +0000
parents 39d1a4ecdee6
children
line wrap: on
line diff
--- a/mod_invites_register_web/mod_invites_register_web.lua	Wed Dec 22 14:48:46 2021 +0000
+++ b/mod_invites_register_web/mod_invites_register_web.lua	Wed Dec 22 15:05:31 2021 +0000
@@ -16,6 +16,7 @@
 });
 
 module:depends("register_apps");
+local mod_password_policy = module:depends("password_policy");
 
 local site_name = module:get_option_string("site_name", module.host);
 local site_apps = module:shared("register_apps/apps");
@@ -59,6 +60,7 @@
 		jid = invite.jid;
 		inviter = invite.inviter;
 		app = query_params.c and site_apps[query_params.c];
+		password_policy = mod_password_policy.get_policy();
 	});
 	return invite_page;
 end
@@ -92,6 +94,7 @@
 			uri = invite.uri;
 			type = invite.type;
 			jid = invite.jid;
+			password_policy = mod_password_policy.get_policy();
 
 			msg_class = "alert-warning";
 			message = "Please fill in all fields.";
@@ -109,6 +112,7 @@
 			uri = invite.uri;
 			type = invite.type;
 			jid = invite.jid;
+			password_policy = mod_password_policy.get_policy();
 
 			msg_class = "alert-warning";
 			message = "This username contains invalid characters.";
@@ -123,12 +127,31 @@
 			uri = invite.uri;
 			type = invite.type;
 			jid = invite.jid;
+			password_policy = mod_password_policy.get_policy();
 
 			msg_class = "alert-warning";
 			message = "This username is already in use.";
 		});
 	end
 
+	local pw_ok, pw_error = mod_password_policy.check_password(password, {
+		username = prepped_username;
+	});
+	if not pw_ok then
+		return render_html_template(register_page_template, {
+			site_name = site_name;
+			token = invite.token;
+			domain = module.host;
+			uri = invite.uri;
+			type = invite.type;
+			jid = invite.jid;
+			password_policy = mod_password_policy.get_policy();
+
+			msg_class = "alert-warning";
+			message = pw_error;
+		});
+	end
+
 	local registering = {
 		validated_invite = invite;
 		username = prepped_username;