names are always saved lowercase
This commit is contained in:
@@ -55,7 +55,6 @@ func Login(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
user, err := storage.GetUserByUsername(creds.Username)
|
user, err := storage.GetUserByUsername(creds.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println("user " + creds.Username + " not found")
|
|
||||||
http.Error(w, "Invalid credentials", http.StatusUnauthorized)
|
http.Error(w, "Invalid credentials", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"shap-planner-backend/models"
|
"shap-planner-backend/models"
|
||||||
|
"strings"
|
||||||
|
|
||||||
_ "github.com/glebarez/go-sqlite"
|
_ "github.com/glebarez/go-sqlite"
|
||||||
)
|
)
|
||||||
@@ -58,11 +59,11 @@ func InitDB(filepath string) error {
|
|||||||
|
|
||||||
// Users
|
// Users
|
||||||
func AddUser(user models.User) error {
|
func AddUser(user models.User) error {
|
||||||
_, err := DB.Exec("INSERT INTO users(id, username, password, role) VALUES (?, ?, ?, ?)", user.ID, user.Username, user.Password, user.Role)
|
_, err := DB.Exec("INSERT INTO users(id, username, password, role) VALUES (?, ?, ?, ?)", user.ID, strings.ToLower(user.Username), user.Password, user.Role)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func GetUserByUsername(username string) (models.User, error) {
|
func GetUserByUsername(username string) (models.User, error) {
|
||||||
row := DB.QueryRow("SELECT * FROM users WHERE username = ?", username)
|
row := DB.QueryRow("SELECT * FROM users WHERE username = ?", strings.ToLower(username))
|
||||||
var user models.User
|
var user models.User
|
||||||
err := row.Scan(&user.ID, &user.Username, &user.Password, &user.Role)
|
err := row.Scan(&user.ID, &user.Username, &user.Password, &user.Role)
|
||||||
return user, err
|
return user, err
|
||||||
@@ -70,7 +71,7 @@ func GetUserByUsername(username string) (models.User, error) {
|
|||||||
func GetUserById(id string) (models.User, error) {
|
func GetUserById(id string) (models.User, error) {
|
||||||
row := DB.QueryRow("SELECT * FROM users WHERE id = ?", id)
|
row := DB.QueryRow("SELECT * FROM users WHERE id = ?", id)
|
||||||
var user models.User
|
var user models.User
|
||||||
err := row.Scan(&user.ID, &user.Username, &user.Password)
|
err := row.Scan(&user.ID, &user.Username, &user.Password, &user.Role)
|
||||||
return user, err
|
return user, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user