26 lines
551 B
Go
26 lines
551 B
Go
package models
|
|
|
|
import "github.com/jinzhu/gorm"
|
|
|
|
type Auth struct {
|
|
ID int `gorm:"primary_key" json:"id"`
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
// CheckAuth checks if authentication information exists
|
|
func CheckAuth(username, password string) (bool, error) {
|
|
var auth Auth
|
|
err := db.Select("id").Where(Auth{Username: username, Password: password}).First(&auth).Error
|
|
if err != nil && err != gorm.ErrRecordNotFound {
|
|
return false, err
|
|
}
|
|
|
|
if auth.ID > 0 {
|
|
return true, nil
|
|
}
|
|
|
|
return false, nil
|
|
}
|
|
|