mod_auth_sql: Add users iterator

Fri, 05 Oct 2012 19:34:53 +0200

author
Kim Alvefur <zash@zash.se>
date
Fri, 05 Oct 2012 19:34:53 +0200
changeset 843
cdc67f4efde2
parent 842
32df4d13f178
child 844
a0987c0e4e1d

mod_auth_sql: Add users iterator

mod_auth_sql/mod_auth_sql.lua file | annotate | diff | comparison | revisions
--- a/mod_auth_sql/mod_auth_sql.lua	Fri Oct 05 16:57:34 2012 +0200
+++ b/mod_auth_sql/mod_auth_sql.lua	Fri Oct 05 19:34:53 2012 +0200
@@ -114,4 +114,18 @@
 	return new_sasl(module.host, profile);
 end
 
+function provider.users()
+	local stmt, err = getsql("SELECT `username` FROM `authreg` WHERE `realm`=?", module.host);
+	if stmt then
+		local next, state = stmt:rows(true)
+		return function()
+			for row in next, state do
+				return row.username;
+			end
+		end
+	end
+	return stmt, err;
+end
+
+
 module:provides("auth", provider);

mercurial