Diff

plugins/mod_storage_xep0227.lua @ 6703:353a7d4dfdc2

mod_storage_xep0227: Store data from mod_auth_internal_hashed in a private namespace
author Kim Alvefur <zash@zash.se>
date Fri, 15 May 2015 15:32:21 +0200
parent 6702:6a5c6c95cf78
child 6704:03afecdf2e3c
line wrap: on
line diff
--- a/plugins/mod_storage_xep0227.lua	Fri May 15 15:30:38 2015 +0200
+++ b/plugins/mod_storage_xep0227.lua	Fri May 15 15:32:21 2015 +0200
@@ -66,19 +66,36 @@
 
 local handlers = {};
 
+-- In order to support mod_auth_internal_hashed
+local extended = "http://prosody.im/protocol/extended-xep0227\1";
+
 handlers.accounts = {
 	get = function(self, user)
 		local user = getUserElement(getXml(user, self.host));
 		if user and user.attr.password then
 			return { password = user.attr.password };
+		elseif user then
+			local data = {};
+			for k, v in pairs(user.attr) do
+				if k:sub(1, #extended) == extended then
+					data[k:sub(#extended+1)] = v;
+				end
+			end
+			return data;
 		end
 	end;
 	set = function(self, user, data)
-		if data and data.password then
+		if data then
 			local xml = getXml(user, self.host);
 			if not xml then xml = createOuterXml(user, self.host); end
 			local usere = getUserElement(xml);
-			usere.attr.password = data.password;
+			for k, v in pairs(data) do
+				if k == "password" then
+					usere.attr.password = v;
+				else
+					usere.attr[extended..k] = v;
+				end
+			end
 			return setXml(user, self.host, xml);
 		else
 			return setXml(user, self.host, nil);