kukkubukku/controller/backend.sh

47 lines
985 B
Bash
Raw Permalink Normal View History

#!/bin/bash
route GET "/backend" backendHome
backendHome() {
requireLoggedIn
2022-03-30 18:41:59 +00:00
htmlContent
endHeaders
2022-03-30 18:41:59 +00:00
title="Backend"
2022-03-30 18:41:59 +00:00
content="$(getRecipesByUsername "$username" | template "templates/backend.fragment.templ")"
template "templates/layout.html.templ"
}
2022-03-30 20:07:35 +00:00
route GET "/backend/new" backendNew
backendNew() {
requireLoggedIn
htmlContent
endHeaders
title="Backend - New"
content="$(template "templates/backend.new.fragment.templ")"
template "templates/layout.html.templ"
}
route POST "/backend/new" backendAdd
backendAdd() {
requireLoggedIn
cacheFormData
name="$(formData "name")"
description="$(formData "description")"
qts="$(formData "qts")"
ingredients="$(formData "ingredients")"
tags="$(formData "tags" | tr '[:upper:]' '[:lower:]')"
2022-03-30 20:07:35 +00:00
if test "$(echo "$qts" | wc -l)" -ne "$(echo "$ingredients" | wc -l)"; then
status 400
endHeaders
return
fi
addRecipe "$name" "$description" "$username" "$qts" "$ingredients" "$tags"
2022-03-30 20:07:35 +00:00
redirect "/backend"
endHeaders
}