really basic login
This commit is contained in:
parent
177a26a2e9
commit
539a36dffe
6 changed files with 116 additions and 50 deletions
|
@ -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
|
||||
}
|
||||
|
|
Reference in a new issue