diff --git a/views/pages/groups.go b/views/pages/groups.go index dbe4260..7554467 100644 --- a/views/pages/groups.go +++ b/views/pages/groups.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "github.com/ordinary-dev/phoenix/database" ) @@ -11,7 +12,7 @@ import ( func CreateGroup(w http.ResponseWriter, r *http.Request) { // Save new group to the database. group := database.Group{ - Name: r.FormValue("groupName"), + Name: strings.TrimSpace(r.FormValue("groupName")), } if err := database.CreateGroup(&group); err != nil { @@ -30,7 +31,8 @@ func UpdateGroup(w http.ResponseWriter, r *http.Request) { return } - if err := database.UpdateGroup(int(id), r.FormValue("groupName")); err != nil { + newName := strings.TrimSpace(r.FormValue("groupName")) + if err := database.UpdateGroup(int(id), newName); err != nil { ShowError(w, http.StatusInternalServerError, err) return } diff --git a/views/pages/links.go b/views/pages/links.go index 0a5f9c6..692f7f7 100644 --- a/views/pages/links.go +++ b/views/pages/links.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "github.com/ordinary-dev/phoenix/database" ) @@ -16,11 +17,11 @@ func CreateLink(w http.ResponseWriter, r *http.Request) { } link := database.Link{ - Name: r.FormValue("linkName"), - Href: r.FormValue("href"), + Name: strings.TrimSpace(r.FormValue("linkName")), + Href: strings.TrimSpace(r.FormValue("href")), GroupID: groupID, } - icon := r.FormValue("icon") + icon := strings.TrimSpace(r.FormValue("icon")) if icon == "" { link.Icon = nil } else { @@ -48,9 +49,9 @@ func UpdateLink(w http.ResponseWriter, r *http.Request) { return } - link.Name = r.FormValue("linkName") - link.Href = r.FormValue("href") - icon := r.FormValue("icon") + link.Name = strings.TrimSpace(r.FormValue("linkName")) + link.Href = strings.TrimSpace(r.FormValue("href")) + icon := strings.TrimSpace(r.FormValue("icon")) if icon == "" { link.Icon = nil } else { diff --git a/views/pages/registration.go b/views/pages/registration.go index 2182aea..8733a9d 100644 --- a/views/pages/registration.go +++ b/views/pages/registration.go @@ -3,6 +3,7 @@ package pages import ( "errors" "net/http" + "strings" "github.com/ordinary-dev/phoenix/database" "github.com/ordinary-dev/phoenix/jwttoken" @@ -41,8 +42,8 @@ func CreateUser(w http.ResponseWriter, r *http.Request) { } // Try to create a user. - username := r.FormValue("username") - password := r.FormValue("password") + username := strings.TrimSpace(r.FormValue("username")) + password := strings.TrimSpace(r.FormValue("password")) _, err = database.CreateAdmin(username, password) if err != nil { ShowError(w, http.StatusInternalServerError, err) diff --git a/views/pages/signin.go b/views/pages/signin.go index c848bf7..b02484e 100644 --- a/views/pages/signin.go +++ b/views/pages/signin.go @@ -2,6 +2,7 @@ package pages import ( "net/http" + "strings" log "github.com/sirupsen/logrus" @@ -23,8 +24,8 @@ func ShowSignInForm(w http.ResponseWriter, _ *http.Request) { func AuthorizeUser(w http.ResponseWriter, r *http.Request) { // Check credentials. - username := r.FormValue("username") - password := r.FormValue("password") + username := strings.TrimSpace(r.FormValue("username")) + password := strings.TrimSpace(r.FormValue("password")) _, err := database.GetAdminIfPasswordMatches(username, password) if err != nil { ShowError(w, http.StatusUnauthorized, err)