diff --git a/Lab01/app/database/database.go b/Lab01/app/database/database.go index d1a18a0..eac4ab8 100644 --- a/Lab01/app/database/database.go +++ b/Lab01/app/database/database.go @@ -13,6 +13,10 @@ func migrateInitial(orm *gorm.DB) { if err != nil { fmt.Println(fmt.Errorf("failed to migrate User")) } + err = orm.AutoMigrate(&Task{}) + if err != nil { + fmt.Println(fmt.Errorf("failed to migrate Task")) + } } func (db *Database) Initialize() { diff --git a/Lab01/app/database/types.go b/Lab01/app/database/types.go index e1b2d2e..081dbda 100644 --- a/Lab01/app/database/types.go +++ b/Lab01/app/database/types.go @@ -14,3 +14,9 @@ type User struct { Password string LoggedIn bool } + +type Task struct { + ID int `gorm:"primaryKey"` + Description string + Done bool +} diff --git a/Lab01/app/templates/_base.tmpl b/Lab01/app/templates/_base.tmpl index 6702099..4fdaf5f 100644 --- a/Lab01/app/templates/_base.tmpl +++ b/Lab01/app/templates/_base.tmpl @@ -22,13 +22,13 @@
@@ -96,8 +96,13 @@ } async function userLoggedIn() { - const response = await fetch("/user", {method: 'GET', headers: myHeaders}); + const response = await fetch("/auth/user", {method: 'GET', headers: myHeaders}); const json = await response.json(); + if (json.logged_in === true) { + document.getElementById("button-login").hidden = true; + button_logout.hidden = false; + document.getElementById("button-tasks").hidden = false; + } return json.logged_in } @@ -105,7 +110,7 @@ button_logout.disabled = true; let data = new FormData(); data.append("username", username); - const response = await fetch("/logout", {method: 'POST', body: data}); + const response = await fetch("/auth/logout", {method: 'POST', body: data}); deleteCookie("username"); response.ok && redirect("/"); } diff --git a/Lab01/app/templates/login.tmpl b/Lab01/app/templates/login.tmpl index a212568..339755b 100644 --- a/Lab01/app/templates/login.tmpl +++ b/Lab01/app/templates/login.tmpl @@ -21,13 +21,13 @@ userLoggedIn().then((loggedIn) => loggedIn && redirect("/")); async function submitForm(formData) { - const response = await fetch("/login", {method: 'POST', body: formData, redirect: 'follow'}); + const response = await fetch("/auth/login", {method: 'POST', body: formData, redirect: 'follow'}); if (response.ok) { const json = await response.json(); setCookie("username", json.username, 1); redirect("/"); } else { - redirect("/login"); + redirect("/view/login"); } } diff --git a/Lab01/app/templates/register.tmpl b/Lab01/app/templates/register.tmpl index c88532c..d5b887a 100644 --- a/Lab01/app/templates/register.tmpl +++ b/Lab01/app/templates/register.tmpl @@ -19,11 +19,11 @@ {{template "formScripts" .}} diff --git a/Lab01/app/templates/tasks.tmpl b/Lab01/app/templates/tasks.tmpl index 91bfa0e..ed9629a 100644 --- a/Lab01/app/templates/tasks.tmpl +++ b/Lab01/app/templates/tasks.tmpl @@ -15,7 +15,7 @@ {{template "scripts" .}}