// Return user given an ID. This is the second function to make *User fulfill // the LoginModel interface func (_ *User) GetById(id uint, g *grapi.Grapi) (grapi.LoginModel, error) { user := User{} if g.DB().Where("id = ?", id).Find(&user).RecordNotFound() { return &user, errors.New("User not found") } return &user, nil }
// Check the login details. func (_ *User) CheckLoginDetails(j *map[string]interface{}, g *grapi.Grapi) (uint, error) { user := User{} fmt.Printf("Checking login details\n") if g.DB().Where("name = ? AND password = ?", (*j)["name"], (*j)["password"]).Find(&user).RecordNotFound() { fmt.Printf("Not found\n") return 0, errors.New("Not authenticated") } else { fmt.Printf("Found user %v\n", user) return user.ID, nil } }