Mercurial > prosody-modules
comparison mod_unified_push/mod_unified_push.lua @ 5152:342baedbd1c8
mod_unified_push: Fix storage backend error behaviours and return values
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 14 Jan 2023 16:15:35 +0000 |
parents | 514c8a0e9aa1 |
children | d69cc9a23fad |
comparison
equal
deleted
inserted
replaced
5151:514c8a0e9aa1 | 5152:342baedbd1c8 |
---|---|
59 }; | 59 }; |
60 | 60 |
61 storage = { | 61 storage = { |
62 sign = function (data) | 62 sign = function (data) |
63 local reg_id = id.long(); | 63 local reg_id = id.long(); |
64 local user, host = jid.split(data.sub); | 64 local ok, err = push_store:set(reg_id, data); |
65 if host ~= module.host or not user then | 65 if not ok then |
66 return; | 66 return nil, err; |
67 end | 67 end |
68 push_store:set(reg_id, data); | |
69 return reg_id; | 68 return reg_id; |
70 end; | 69 end; |
71 verify = function (token) | 70 verify = function (token) |
72 if token == "_private" then return nil, "invalid-token"; end | 71 if token == "_private" then return nil, "invalid-token"; end |
73 local data = push_store:get(token); | 72 local data = push_store:get(token); |
75 return nil, "item-not-found"; | 74 return nil, "item-not-found"; |
76 elseif data.exp and data.exp < os.time() then | 75 elseif data.exp and data.exp < os.time() then |
77 push_store:set(token, nil); | 76 push_store:set(token, nil); |
78 return nil, "token-expired"; | 77 return nil, "token-expired"; |
79 end | 78 end |
80 return data; | 79 return true, data; |
81 end; | 80 end; |
82 }; | 81 }; |
83 }; | 82 }; |
84 | 83 |
85 if pcall(require, "util.paseto") and require "util.paseto".v3_local then | 84 if pcall(require, "util.paseto") and require "util.paseto".v3_local then |