diff --git a/controller/backend.sh b/controller/backend.sh new file mode 100644 index 0000000..ef423f7 --- /dev/null +++ b/controller/backend.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +route GET "/backend" backendHome +backendHome() { + requireLoggedIn + endHeaders + + title="Backend" + content="$(template "templates/backend.fragment.templ")" + template "templates/layout.html.templ" +} diff --git a/controller/home.sh b/controller/home.sh new file mode 100644 index 0000000..883218d --- /dev/null +++ b/controller/home.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +route GET "/" home +home() { + htmlContent + endHeaders + + title="Home" + content="$(template "templates/home.fragment.templ")" + template "templates/layout.html.templ" +} diff --git a/controller/users.sh b/controller/users.sh new file mode 100644 index 0000000..a800787 --- /dev/null +++ b/controller/users.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +route GET "/login" loginForm +loginForm() { + htmlContent + endHeaders + + title="Login" + content="$(template "templates/login.fragment.templ")" + template "templates/layout.html.templ" +} + +route POST "/login" login +login() { + username="$(formData "username")" + password="$(formData "password")" + + if loginUser "$username" "$password"; then + echo "ok" + else + echo "ko" + fi +} diff --git a/data/users.sh b/data/users.sh index e73aa58..9916be0 100644 --- a/data/users.sh +++ b/data/users.sh @@ -32,6 +32,7 @@ loginUser() { password="$(hashPassword "$password" "$salt")" - test "$password" = "$hash" + # return true if password is correct + test "$password" != "$hash" return } diff --git a/index.sh b/index.sh index 3746eb6..676efd8 100755 --- a/index.sh +++ b/index.sh @@ -4,9 +4,20 @@ . shochu/uri.sh . shochu/router.sh . shochu/mysql.sh -. shochu/credentials.sh +. shochu/cookies.sh +. shochu/sessions.sh + . shochu/shinden/engine.sh +. utils/auth.sh +. utils/headers.sh + +. data/users.sh + +. controller/users.sh +. controller/home.sh +. controller/backend.sh + connect "$mysqlHost" "$mysqlUser" "$mysqlPassword" "$mysqlDB" router diff --git a/templates/backend.fragment.templ b/templates/backend.fragment.templ new file mode 100644 index 0000000..b741bd8 --- /dev/null +++ b/templates/backend.fragment.templ @@ -0,0 +1,2 @@ +