// getDeveloper retrieves the local dev and updates if out of date, or no // dev exists. func getDeveloper() (*db.Developer, error) { dev, err := db.GetDeveloper() if err != nil && err != errors.ErrNoDeveloper { return dev, err } ok := false if err != nil { log.Println("yellow", "Oops! You must be logged in.") } else { ok, err = devUpToDate(dev) if err != nil { return dev, err } if !ok { log.Println("yellow", "Oops! Your login information is out of date.") } } if err != nil || !ok { err = getToken(dev) if err != nil { return dev, err } } return dev, updateDeveloper(dev) }
func logoutRun(keen *keen.Client, rollbar *rollbar.Client, args ...string) int { dev, err := db.GetDeveloper() if err != nil && err != errors.ErrNoDeveloper { rollbar.Report(err) return 1 } if err == nil { log.Println("", "Logging you out", strings.Split(dev.Developer.Name, " ")[0]+".") } else { log.Println("yellow", "No user logged in.") } dev.Token = "" dev.Developer = nil err = dev.Save() if err != nil { rollbar.Report(err) return 1 } keen.AddEvent("bowery logout", map[string]*db.Developer{"user": dev}) return 0 }
func loginRun(keen *keen.Client, rollbar *rollbar.Client, args ...string) int { dev, err := db.GetDeveloper() if err != nil && err != errors.ErrNoDeveloper { rollbar.Report(err) return 1 } // If dev was found then check if token is up to date. if err == nil { ok, err := devUpToDate(dev) if err != nil { rollbar.Report(err) return 1 } if ok { log.Println("", "You're logged in as", strings.Split(dev.Developer.Name, " ")[0]+".") return 0 } else { log.Println("yellow", "Oops! Your login information is out of date.") } } err = getToken(dev) if err != nil { rollbar.Report(err) return 1 } err = updateDeveloper(dev) if err != nil { rollbar.Report(err) return 1 } keen.AddEvent("bowery login", map[string]*db.Developer{"user": dev}) log.Println("magenta", "Hey there", strings.Split(dev.Developer.Name, " ")[0], "you're logged in now.") return 0 }