Fixed dumb routing mistake
This commit is contained in:
parent
697939a17a
commit
f52674b179
@ -68,6 +68,7 @@ func main() {
|
|||||||
mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(db, store))
|
mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(db, store))
|
||||||
mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(db, store))
|
mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(db, store))
|
||||||
mux.HandleFunc("POST /submit-article/", view.SubmitArticle(db, store))
|
mux.HandleFunc("POST /submit-article/", view.SubmitArticle(db, store))
|
||||||
|
mux.HandleFunc("POST /update-user/", view.UpdateUser(db, store))
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(":8080", mux))
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func (db *DB) UpdateAttributes(a ...*Attribute) error {
|
|||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
log.Fatalf("error: transaction error: %v, rollback error: %v", err, rollbackErr)
|
log.Fatalf("error: transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("error updating article in DB: %v", err)
|
return fmt.Errorf("error updating %v in DB: %v", attribute.AttName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ func (tx *Tx) UpdateAttributes(a ...*Attribute) error {
|
|||||||
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
log.Fatalf("error: transaction error: %v, rollback error: %v", err, rollbackErr)
|
log.Fatalf("error: transaction error: %v, rollback error: %v", err, rollbackErr)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("error updating article in DB: %v", err)
|
return fmt.Errorf("error updating %v in DB: %v", attribute.AttName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +121,27 @@ func AddUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func EditUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
func EditUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
session, err := s.Get(r, "cookie")
|
||||||
|
if err != nil {
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/login.html")
|
||||||
|
msg := "Session nicht mehr gültig. Bitte erneut anmelden."
|
||||||
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := db.GetUser(session.Values["id"].(int64))
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles("web/templates/edit-user.html")
|
||||||
|
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := s.Get(r, "cookie")
|
session, err := s.Get(r, "cookie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -160,13 +181,15 @@ func EditUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := db.GetID(userData.UserName); ok {
|
if id, ok := db.GetID(userData.UserName); ok {
|
||||||
userData.Msg = "Benutzername bereits vergeben."
|
if id != userData.ID {
|
||||||
userData.UserName = ""
|
userData.Msg = "Benutzername bereits vergeben."
|
||||||
tmpl, err := template.ParseFiles("web/templates/edit-user.html")
|
userData.UserName = ""
|
||||||
tmpl = template.Must(tmpl, err)
|
tmpl, err := template.ParseFiles("web/templates/edit-user.html")
|
||||||
tmpl.ExecuteTemplate(w, "page-content", userData)
|
tmpl = template.Must(tmpl, err)
|
||||||
return
|
tmpl.ExecuteTemplate(w, "page-content", userData)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := db.StartTransaction()
|
tx, err := db.StartTransaction()
|
||||||
@ -198,8 +221,8 @@ func EditUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|||||||
|
|
||||||
if err = tx.UpdateAttributes(
|
if err = tx.UpdateAttributes(
|
||||||
&model.Attribute{Table: "users", ID: userData.ID, AttName: "username", Value: userData.UserName},
|
&model.Attribute{Table: "users", ID: userData.ID, AttName: "username", Value: userData.UserName},
|
||||||
&model.Attribute{Table: "users", ID: userData.ID, AttName: "first-name", Value: userData.FirstName},
|
&model.Attribute{Table: "users", ID: userData.ID, AttName: "first_name", Value: userData.FirstName},
|
||||||
&model.Attribute{Table: "users", ID: userData.ID, AttName: "last-name", Value: userData.LastName},
|
&model.Attribute{Table: "users", ID: userData.ID, AttName: "last_name", Value: userData.LastName},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
@ -214,6 +237,6 @@ func EditUser(db *model.DB, s *control.CookieStore) http.HandlerFunc {
|
|||||||
|
|
||||||
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
tmpl, err := template.ParseFiles("web/templates/hub.html")
|
||||||
tmpl = template.Must(tmpl, err)
|
tmpl = template.Must(tmpl, err)
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["Role"].(string))
|
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user