mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-19 19:30:28 +05:00
chore: trim spaces in the received data
This commit is contained in:
parent
6a71891478
commit
101202b128
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue