mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-20 03:40:29 +05:00
chore: trim spaces in the received data
This commit is contained in:
parent
6a71891478
commit
101202b128
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ordinary-dev/phoenix/database"
|
"github.com/ordinary-dev/phoenix/database"
|
||||||
)
|
)
|
||||||
|
@ -11,7 +12,7 @@ import (
|
||||||
func CreateGroup(w http.ResponseWriter, r *http.Request) {
|
func CreateGroup(w http.ResponseWriter, r *http.Request) {
|
||||||
// Save new group to the database.
|
// Save new group to the database.
|
||||||
group := database.Group{
|
group := database.Group{
|
||||||
Name: r.FormValue("groupName"),
|
Name: strings.TrimSpace(r.FormValue("groupName")),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.CreateGroup(&group); err != nil {
|
if err := database.CreateGroup(&group); err != nil {
|
||||||
|
@ -30,7 +31,8 @@ func UpdateGroup(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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)
|
ShowError(w, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ordinary-dev/phoenix/database"
|
"github.com/ordinary-dev/phoenix/database"
|
||||||
)
|
)
|
||||||
|
@ -16,11 +17,11 @@ func CreateLink(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
link := database.Link{
|
link := database.Link{
|
||||||
Name: r.FormValue("linkName"),
|
Name: strings.TrimSpace(r.FormValue("linkName")),
|
||||||
Href: r.FormValue("href"),
|
Href: strings.TrimSpace(r.FormValue("href")),
|
||||||
GroupID: groupID,
|
GroupID: groupID,
|
||||||
}
|
}
|
||||||
icon := r.FormValue("icon")
|
icon := strings.TrimSpace(r.FormValue("icon"))
|
||||||
if icon == "" {
|
if icon == "" {
|
||||||
link.Icon = nil
|
link.Icon = nil
|
||||||
} else {
|
} else {
|
||||||
|
@ -48,9 +49,9 @@ func UpdateLink(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
link.Name = r.FormValue("linkName")
|
link.Name = strings.TrimSpace(r.FormValue("linkName"))
|
||||||
link.Href = r.FormValue("href")
|
link.Href = strings.TrimSpace(r.FormValue("href"))
|
||||||
icon := r.FormValue("icon")
|
icon := strings.TrimSpace(r.FormValue("icon"))
|
||||||
if icon == "" {
|
if icon == "" {
|
||||||
link.Icon = nil
|
link.Icon = nil
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package pages
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ordinary-dev/phoenix/database"
|
"github.com/ordinary-dev/phoenix/database"
|
||||||
"github.com/ordinary-dev/phoenix/jwttoken"
|
"github.com/ordinary-dev/phoenix/jwttoken"
|
||||||
|
@ -41,8 +42,8 @@ func CreateUser(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to create a user.
|
// Try to create a user.
|
||||||
username := r.FormValue("username")
|
username := strings.TrimSpace(r.FormValue("username"))
|
||||||
password := r.FormValue("password")
|
password := strings.TrimSpace(r.FormValue("password"))
|
||||||
_, err = database.CreateAdmin(username, password)
|
_, err = database.CreateAdmin(username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ShowError(w, http.StatusInternalServerError, err)
|
ShowError(w, http.StatusInternalServerError, err)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
@ -23,8 +24,8 @@ func ShowSignInForm(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
|
||||||
func AuthorizeUser(w http.ResponseWriter, r *http.Request) {
|
func AuthorizeUser(w http.ResponseWriter, r *http.Request) {
|
||||||
// Check credentials.
|
// Check credentials.
|
||||||
username := r.FormValue("username")
|
username := strings.TrimSpace(r.FormValue("username"))
|
||||||
password := r.FormValue("password")
|
password := strings.TrimSpace(r.FormValue("password"))
|
||||||
_, err := database.GetAdminIfPasswordMatches(username, password)
|
_, err := database.GetAdminIfPasswordMatches(username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ShowError(w, http.StatusUnauthorized, err)
|
ShowError(w, http.StatusUnauthorized, err)
|
||||||
|
|
Loading…
Reference in a new issue