Compare commits

...

2 Commits

4 changed files with 36 additions and 10 deletions

View File

@ -16,12 +16,15 @@ func HandleLogin(db *data.DB) http.HandlerFunc {
id, err := db.GetID(user)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
// TODO: und nun?
return
}
if err := db.CheckPassword(id, pass); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
} else {
template.Must(template.ParseFiles("web/templates/editor.html")).ExecuteTemplate(w, "page-content", nil)
}
@ -36,8 +39,9 @@ func HandleFinishedEdit(f *feed.Feed) http.HandlerFunc {
content, err := data.ConvertToHTML(mdContent)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Panicln(err)
return
}
feed.AddToFeed(f, title, desc, content)
@ -57,6 +61,10 @@ func HandleAddUser(db *data.DB) http.HandlerFunc {
last := r.PostFormValue("last-name")
role := r.PostFormValue("role")
if inputsEmpty(user, pass, pass2, first, last, role) {
log.Println("inputsEmpty")
template.Must(template.ParseFiles("web/templates/add-user.html")).Execute(w, nil)
}
_, _, ok := checkUserStrings(user, first, last)
if !ok {
log.Println("checkUserStrings")
@ -92,6 +100,7 @@ func HandleAddUser(db *data.DB) http.HandlerFunc {
if err := db.AddUser(user, pass, first, last, writer, editor, admin); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
template.Must(template.ParseFiles("web/templates/editor.html")).Execute(w, nil)
}

View File

@ -1,5 +1,14 @@
package ui
func inputsEmpty(user, pass, pass2, first, last, role string) bool {
return len(user) == 0 ||
len(pass) == 0 ||
len(pass2) == 0 ||
len(first) == 0 ||
len(last) == 0 ||
len(role) == 0
}
func checkUserStrings(user, first, last string) (string, int, bool) {
userLen := 15
nameLen := 50

View File

@ -4,6 +4,7 @@ import (
"html/template"
"log"
"net/http"
"os"
"streifling.com/jason/cpolis/cmd/data"
"streifling.com/jason/cpolis/cmd/feed"
@ -11,6 +12,13 @@ import (
)
func main() {
logFile, err := os.Create("tmp/cpolis.log")
if err != nil {
log.Fatalln(err)
}
defer logFile.Close()
log.SetOutput(logFile)
db, err := data.OpenDB("cpolis")
if err != nil {
log.Fatalln(err)

View File

@ -1,19 +1,19 @@
{{define "page-content"}}
<h2>Neuer Benutzer</h2>
<form>
<input name="username" placeholder="Benutzername" type="text" />
<input name="password" placeholder="Passwort" type="password" />
<input name="password2" placeholder="Passwort wiederholen" type="password" />
<input required name="username" placeholder="Benutzername" type="text" />
<input required name="password" placeholder="Passwort" type="password" />
<input required name="password2" placeholder="Passwort wiederholen" type="password" />
<input name="first-name" placeholder="Vorname" type="text" />
<input name="last-name" placeholder="Nachname" type="text" />
<input required name="first-name" placeholder="Vorname" type="text" />
<input required name="last-name" placeholder="Nachname" type="text" />
<label for="writer">Schreiber</label>
<input id="writer" name="role" type="radio" value="writer" />
<input required id="writer" name="role" type="radio" value="writer" />
<label for="editor">Redakteur</label>
<input id="editor" name="role" type="radio" value="editor" />
<input required id="editor" name="role" type="radio" value="editor" />
<label for="admin">Admin</label>
<input id="admin" name="role" type="radio" value="admin" />
<input required id="admin" name="role" type="radio" value="admin" />
<input type="submit" value="Anlegen" hx-post="/add-user/" hx-target="#page-content" />
</form>