Check if user already exists and bug fix
This commit is contained in:
parent
8ef6b6472d
commit
280e88a526
@ -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 {
|
||||
|
13
cmd/ui/ui.go
13
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)
|
||||
}
|
||||
}
|
||||
|
4
main.go
4
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))
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
{{define "page-content"}}
|
||||
<h2>Neuer Benutzer</h2>
|
||||
<form>
|
||||
<input name="username" placeholder="Benutzername" type="text" />
|
||||
<input name="password" placeholder="Passwort" type="password" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user