really basic login

This commit is contained in:
Florian Hoss 2022-04-04 10:16:29 +02:00
parent 177a26a2e9
commit 539a36dffe
6 changed files with 116 additions and 50 deletions

View file

@ -23,3 +23,21 @@ func (db *Database) Initialize() {
migrateInitial(orm)
db.ORM = orm
}
func (db *Database) CreateUser(username string, password string) error {
user := User{Username: username, Password: password}
result := db.ORM.Create(&user)
return result.Error
}
func (db *Database) LoginUser(username string, password string) (bool, error) {
user := User{Username: username, Password: password}
result := db.ORM.Where("username = ? AND password = ?", username, password).Find(&user)
if result.Error != nil {
return false, result.Error
}
if result.RowsAffected == 1 {
return true, nil
}
return false, nil
}