unstable: initial tags

This commit is contained in:
ston1th 2019-08-20 23:57:43 +02:00
commit b3b62af3a4
28 changed files with 503 additions and 91 deletions

View file

@ -7,6 +7,7 @@ import (
"git.giftfish.de/ston1th/docstore/pkg/fs"
"git.giftfish.de/ston1th/docstore/pkg/log"
"git.giftfish.de/ston1th/docstore/pkg/otp"
"git.giftfish.de/ston1th/docstore/pkg/tags"
"git.giftfish.de/ston1th/jwt/v3"
"html/template"
"net/http"
@ -197,12 +198,17 @@ func indexHandler(ctx *Context) {
log.Printf("scanner: %s: %s", path, err)
return
}
id, err := ctx.Srv.DB.Index.Add(txt)
t, err := ctx.Srv.DB.GetAllTags()
if err != nil {
log.Printf("getTags: %s: %s", path, err)
}
found := tags.Find(txt, t)
id, err := ctx.Srv.DB.Index.Add(txt, found)
if err != nil {
log.Printf("index: %s: %s", path, err)
return
}
err = ctx.Srv.DB.NewFile(id, file)
err = ctx.Srv.DB.NewFile(id, file, found)
if err != nil {
log.Printf("newFile: %s: %s", path, err)
}
@ -687,6 +693,94 @@ func userTotpHandler(ctx *Context) {
}
}
func tagsHandler(ctx *Context) {
ctx.Template("tagsHandler")
ctx.Data = webData{
Title: "Tags",
BodyTitle: "Tags",
}
t, err := ctx.Srv.DB.GetAllTags()
if err != nil {
ctx.Error(err)
return
}
ctx.Data.Data = t
switch ctx.Method() {
case "GET":
ctx.Exec()
}
}
func tagsEditHandler(ctx *Context) {
ctx.Template("tagsEditHandler")
ctx.Data = webData{
Title: "Edit User",
BodyTitle: "Edit User",
}
u, err := ctx.Srv.DB.GetUserWithoutPassword()
if err != nil {
ctx.Error(err)
return
}
ctx.Data.Data = u
switch ctx.Method() {
case "GET":
ctx.Exec()
case "POST":
if !ctx.CheckXsrf() {
return
}
password := ctx.Form("password")
repeat := ctx.Form("repeat")
if password != repeat {
ctx.Error("passwords do not match")
return
}
if err := ctx.Srv.DB.UpdateUserPassword(password); err != nil {
ctx.Error(err)
return
}
log.Printf("update: %s updated\n", ctx.User())
ctx.Redirect(core.IndexURI, http.StatusFound)
}
}
func tagsDelHandler(ctx *Context) {
ctx.Template("tagsDelHandler")
ctx.Data = webData{
Title: "Edit User",
BodyTitle: "Edit User",
}
u, err := ctx.Srv.DB.GetUserWithoutPassword()
if err != nil {
ctx.Error(err)
return
}
ctx.Data.Data = u
switch ctx.Method() {
case "GET":
ctx.Exec()
case "POST":
if !ctx.CheckXsrf() {
return
}
password := ctx.Form("password")
repeat := ctx.Form("repeat")
if password != repeat {
ctx.Error("passwords do not match")
return
}
if err := ctx.Srv.DB.UpdateUserPassword(password); err != nil {
ctx.Error(err)
return
}
log.Printf("update: %s updated\n", ctx.User())
ctx.Redirect(core.IndexURI, http.StatusFound)
}
}
func logoutHandler(ctx *Context) {
user := ctx.User()
if user == "" {