Comparison

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
comparison
equal deleted inserted replaced
6702:6a5c6c95cf78 6703:353a7d4dfdc2
64 removeFromArray(s, child); 64 removeFromArray(s, child);
65 end 65 end
66 66
67 local handlers = {}; 67 local handlers = {};
68 68
69 -- In order to support mod_auth_internal_hashed
70 local extended = "http://prosody.im/protocol/extended-xep0227\1";
71
69 handlers.accounts = { 72 handlers.accounts = {
70 get = function(self, user) 73 get = function(self, user)
71 local user = getUserElement(getXml(user, self.host)); 74 local user = getUserElement(getXml(user, self.host));
72 if user and user.attr.password then 75 if user and user.attr.password then
73 return { password = user.attr.password }; 76 return { password = user.attr.password };
77 elseif user then
78 local data = {};
79 for k, v in pairs(user.attr) do
80 if k:sub(1, #extended) == extended then
81 data[k:sub(#extended+1)] = v;
82 end
83 end
84 return data;
74 end 85 end
75 end; 86 end;
76 set = function(self, user, data) 87 set = function(self, user, data)
77 if data and data.password then 88 if data then
78 local xml = getXml(user, self.host); 89 local xml = getXml(user, self.host);
79 if not xml then xml = createOuterXml(user, self.host); end 90 if not xml then xml = createOuterXml(user, self.host); end
80 local usere = getUserElement(xml); 91 local usere = getUserElement(xml);
81 usere.attr.password = data.password; 92 for k, v in pairs(data) do
93 if k == "password" then
94 usere.attr.password = v;
95 else
96 usere.attr[extended..k] = v;
97 end
98 end
82 return setXml(user, self.host, xml); 99 return setXml(user, self.host, xml);
83 else 100 else
84 return setXml(user, self.host, nil); 101 return setXml(user, self.host, nil);
85 end 102 end
86 end; 103 end;