mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-29 16:24:58 +00:00
29 lines
902 B
Lua
29 lines
902 B
Lua
local M = {}
|
|
|
|
function M.login(data)
|
|
local errors = {}
|
|
if not data.username or data.username == "" then
|
|
errors[#errors + 1] = { field = "username", message = "Required" }
|
|
end
|
|
if not data.password or #data.password < 6 then
|
|
errors[#errors + 1] = { field = "password", message = "Min 6 chars" }
|
|
end
|
|
return { valid = #errors == 0, errors = errors }
|
|
end
|
|
|
|
function M.register(data)
|
|
local errors = {}
|
|
if not data.username or #data.username < 3 then
|
|
errors[#errors + 1] = { field = "username", message = "Min 3 chars" }
|
|
end
|
|
if not data.email or not string.match(data.email, "^[^@]+@[^@]+%.[^@]+$") then
|
|
errors[#errors + 1] = { field = "email", message = "Invalid email" }
|
|
end
|
|
if not data.password or #data.password < 8 then
|
|
errors[#errors + 1] = { field = "password", message = "Min 8 chars" }
|
|
end
|
|
return { valid = #errors == 0, errors = errors }
|
|
end
|
|
|
|
return M
|