2018-08-28 10:49:12 +02:00
|
|
|
BaseController:subclass(
|
|
|
|
"UserController",
|
|
|
|
{
|
|
|
|
models = {"user"}
|
|
|
|
}
|
|
|
|
)
|
2018-08-23 15:22:59 +02:00
|
|
|
|
|
|
|
function UserController:index(...)
|
|
|
|
local args = {...}
|
|
|
|
local data = self.user:findAll()
|
2018-08-28 10:49:12 +02:00
|
|
|
if not data or not data[1] then
|
2018-08-23 15:22:59 +02:00
|
|
|
self:error("Cannot fetch user info")
|
|
|
|
end
|
2020-06-07 19:46:59 +02:00
|
|
|
data[1].user = self.registry.user
|
2018-08-23 15:22:59 +02:00
|
|
|
self.template:set("data", data[1])
|
|
|
|
return true
|
2018-08-28 10:49:12 +02:00
|
|
|
end
|
2021-01-05 20:12:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
function UserController:photo(...)
|
|
|
|
local data = self.user:findAll()
|
|
|
|
if not data or not data[1] then
|
|
|
|
self:error("Cannot fetch user info")
|
|
|
|
end
|
|
|
|
if(not data[1] or data[1].photo == "") then
|
|
|
|
self:error("User photo is not available")
|
|
|
|
end
|
|
|
|
local prefix = data[1].photo:match("%a+://")
|
|
|
|
local suffix = data[1].photo:gsub(prefix,"")
|
|
|
|
local path = string.format("/home/%s/", self.registry.user)..suffix
|
|
|
|
print(path)
|
|
|
|
if ulib.exists(path) then
|
|
|
|
local mime = std.mimeOf(path)
|
|
|
|
std.sendFile(path)
|
|
|
|
else
|
|
|
|
self:error("Asset file not found or access forbidden: "..path)
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|