mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
added handle column to provide case insensitive constraint
This commit is contained in:
parent
3c617c2829
commit
fae657d356
@ -80,6 +80,7 @@ func AddAccount(w http.ResponseWriter, r *http.Request) {
|
||||
// create new account
|
||||
account := store.Account{
|
||||
Username: username,
|
||||
Handle: strings.ToLower(username),
|
||||
Password: password,
|
||||
Guid: fingerprint,
|
||||
}
|
||||
|
@ -41,17 +41,27 @@ func GetAccountUsername(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var accounts []accountUsername;
|
||||
err := store.DB.Model(&store.Account{}).Where("username = ?", username).Find(&accounts).Error
|
||||
if err != nil {
|
||||
if err := store.DB.Model(&store.Account{}).Where("username = ?", username).Find(&accounts).Error; err != nil {
|
||||
LogMsg("failed to query accounts")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if len(accounts) == 0 {
|
||||
WriteResponse(w, true)
|
||||
} else {
|
||||
if len(accounts) != 0 {
|
||||
WriteResponse(w, false)
|
||||
return
|
||||
}
|
||||
|
||||
handle := strings.ToLower(username);
|
||||
if err := store.DB.Model(&store.Account{}).Where("handle = ?", handle).Find(&accounts).Error; err != nil {
|
||||
LogMsg("failed to query accounts")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if len(accounts) != 0 {
|
||||
WriteResponse(w, false)
|
||||
return
|
||||
}
|
||||
|
||||
WriteResponse(w, true)
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package databag
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"net/http"
|
||||
"gorm.io/gorm"
|
||||
"databag/internal/store"
|
||||
@ -26,6 +27,7 @@ func SetAccountAuthentication(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
token.Account.Username = username;
|
||||
token.Account.Handle = strings.ToLower(username);
|
||||
token.Account.Password = password;
|
||||
err := store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if res := tx.Save(token.Account).Error; res != nil {
|
||||
|
@ -57,6 +57,7 @@ type Account struct {
|
||||
AccountDetailID uint `gorm:"not null"`
|
||||
Guid string `gorm:"not null;uniqueIndex"`
|
||||
Username string `gorm:"not null;uniqueIndex"`
|
||||
Handle string `gorm:"uniqueIndex"`
|
||||
Password []byte `gorm:"not null"`
|
||||
AccountRevision int64 `gorm:"not null;default:1"`
|
||||
ProfileRevision int64 `gorm:"not null;default:1"`
|
||||
|
Loading…
Reference in New Issue
Block a user