diff --git a/main.go b/main.go index c4442bf..aa45131 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,8 @@ func main() { values := config.ReadConfig("config.json") views.PopulateTemplates() http.HandleFunc("/", views.ShowAllTasksFunc) + http.HandleFunc("/login/", views.LoginFunc) + http.HandleFunc("/logout/", views.LogoutFunc) http.HandleFunc("/add-category/", views.AddCategoryFunc) http.HandleFunc("/add-comment/", views.AddCommentFunc) http.HandleFunc("/del-comment/", views.DeleteCommentFunc) diff --git a/sessions/sessions.go b/sessions/sessions.go new file mode 100755 index 0000000..be955c6 --- /dev/null +++ b/sessions/sessions.go @@ -0,0 +1,19 @@ +package sessions + +import ( + "net/http" + + "github.com/gorilla/sessions" +) + +//Store the cookie store which is going to store session data in the cookie +var Store = sessions.NewCookieStore([]byte("secret-password")) + +//IsLoggedIn will check if the user has an active session and return True +func IsLoggedIn(r *http.Request) bool { + session, _ := Store.Get(r, "session") + if session.Values["loggedin"] == "true" { + return true + } + return false +} diff --git a/templates/_head.html b/templates/_head.html index 724d4b9..efa6936 100644 --- a/templates/_head.html +++ b/templates/_head.html @@ -75,6 +75,7 @@ {{end}} + diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..47d3ae1 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,36 @@ +