mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
restrict whitespace from usernames
This commit is contained in:
parent
b4c019abf8
commit
31fd45890a
@ -2,6 +2,7 @@ package databag
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
@ -36,6 +37,11 @@ func AddAccount(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(username, " ") || strings.Contains(username, "\t") {
|
||||||
|
ErrResponse(w, http.StatusConflict, errors.New("username has whitespace"));
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// check if username is taken
|
// check if username is taken
|
||||||
var count int64
|
var count int64
|
||||||
if err := store.DB.Model(&store.Account{}).Where("username = ?", username).Count(&count).Error; err != nil {
|
if err := store.DB.Model(&store.Account{}).Where("username = ?", username).Count(&count).Error; err != nil {
|
||||||
|
@ -2,6 +2,7 @@ package databag
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
"net/http"
|
"net/http"
|
||||||
"databag/internal/store"
|
"databag/internal/store"
|
||||||
)
|
)
|
||||||
@ -34,6 +35,11 @@ func GetAccountUsername(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(username, " ") || strings.Contains(username, "\t") {
|
||||||
|
WriteResponse(w, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var accounts []accountUsername;
|
var accounts []accountUsername;
|
||||||
err := store.DB.Model(&store.Account{}).Where("username = ?", username).Find(&accounts).Error
|
err := store.DB.Model(&store.Account{}).Where("username = ?", username).Find(&accounts).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user