diff --git a/cmd/data/db.go b/cmd/data/db.go index 53fb868..fca84c4 100644 --- a/cmd/data/db.go +++ b/cmd/data/db.go @@ -44,7 +44,7 @@ func (db *DB) AddUser(user, pass, first, last string, writer, editor, admin bool INSERT INTO users (username, password, first_name, last_name, writer, editor, admin) VALUES - (?, ?, ?, ?, ?, ?) + (?, ?, ?, ?, ?, ?, ?) ` _, err = db.Exec(query, user, string(hashedPass), first, last, writer, editor, admin) if err != nil { diff --git a/cmd/ui/ui.go b/cmd/ui/ui.go index 6cd7ef1..4a7c582 100644 --- a/cmd/ui/ui.go +++ b/cmd/ui/ui.go @@ -59,9 +59,16 @@ func HandleAddUser(db *data.DB) http.HandlerFunc { _, _, ok := checkUserStrings(user, first, last) if !ok { + log.Println("checkUserStrings") + template.Must(template.ParseFiles("web/templates/add-user.html")).Execute(w, nil) + } + id, _ := db.GetID(user) + if id != 0 { + log.Println("GetID") template.Must(template.ParseFiles("web/templates/add-user.html")).Execute(w, nil) } if pass != pass2 { + log.Println("pass") template.Must(template.ParseFiles("web/templates/add-user.html")).Execute(w, nil) } switch role { @@ -78,10 +85,14 @@ func HandleAddUser(db *data.DB) http.HandlerFunc { editor = false admin = true default: + log.Println("switch") template.Must(template.ParseFiles("web/templates/add-user.html")).Execute(w, nil) } - db.AddUser(user, pass, first, last, writer, editor, admin) + if err := db.AddUser(user, pass, first, last, writer, editor, admin); err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + } template.Must(template.ParseFiles("web/templates/editor.html")).Execute(w, nil) } } diff --git a/main.go b/main.go index 6e9b8d8..5996983 100644 --- a/main.go +++ b/main.go @@ -30,8 +30,10 @@ func main() { mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { template.Must(template.ParseFiles("web/templates/index.html", "web/templates/login.html")).Execute(w, nil) }) - mux.HandleFunc("POST /login/", ui.HandleLogin(db)) + + mux.HandleFunc("POST /add-user/", ui.HandleAddUser(db)) mux.HandleFunc("POST /finished-edit/", ui.HandleFinishedEdit(rss)) + mux.HandleFunc("POST /login/", ui.HandleLogin(db)) log.Fatalln(http.ListenAndServe(":8080", mux)) } diff --git a/web/templates/add-user.html b/web/templates/add-user.html index b238bd7..4341202 100644 --- a/web/templates/add-user.html +++ b/web/templates/add-user.html @@ -1,4 +1,5 @@ {{define "page-content"}} +