make default avatar use the avatars table
This commit is contained in:
25
util.lua
25
util.lua
@ -34,9 +34,6 @@ util.TransientUser = {
|
||||
}
|
||||
|
||||
function util.get_user_avatar_url(req, user)
|
||||
if not user.avatar_id then
|
||||
return "/avatars/default.webp"
|
||||
end
|
||||
return Avatars:find(user.avatar_id).file_path
|
||||
end
|
||||
|
||||
@ -72,6 +69,28 @@ function util.validate_and_create_image(input_image, filename)
|
||||
return true
|
||||
end
|
||||
|
||||
function util.destroy_avatar(avatar_id)
|
||||
if avatar_id == 1 then
|
||||
print("won't delete default avatar")
|
||||
return
|
||||
end
|
||||
|
||||
local avatar = Avatars:find(avatar_id)
|
||||
|
||||
if not avatar then
|
||||
return
|
||||
end
|
||||
|
||||
local file_path = "static" .. avatar.file_path
|
||||
local f = io.open(file_path, "r")
|
||||
if not f then
|
||||
print("can't open avatar file")
|
||||
else
|
||||
f:close()
|
||||
os.remove(file_path)
|
||||
end
|
||||
end
|
||||
|
||||
function util.get_logged_in_user(req)
|
||||
if req.session.session_key == nil then
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user