Ejemplo n.º 1
0
// Logs in to github using oauth.
// Returns error if login fails.
func Login(userkey string) error {
	file, err := ioutil.ReadFile(*Path + ".issue/config.json")
	if err != nil {
		GitLog.Println("open config: ", err)
		os.Exit(1)
	}
	temp := new(Config)
	if err = json.Unmarshal(file, temp); err != nil {
		GitLog.Println("parse config: ", err)
		os.Exit(1)
	}
	Conf = temp
	token := Conf.Token
	if Conf.Secure {
		key := []byte(userkey)
		token = encrypt.Decrypt(key, token)
	}
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: token},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)
	client = github.NewClient(tc)
	user, _, err := client.Users.Get("")

	if err != nil {
		GitLog.Printf("\nerror: %v\n", err)
		return err
	}
	log.Printf("\nLogged into: %v\n", github.Stringify(user.Login))
	GitLog.Print("Logged into: ", github.Stringify(user.Login))
	return nil
}
Ejemplo n.º 2
0
// Change user encyption key
func ChangeKey(oldKey, newKey string) error {
	file, err := ioutil.ReadFile(*Path + ".issue/config.json")
	if err != nil {
		GitLog.Println("open config: ", err)
		os.Exit(1)
	}
	temp := new(Config)
	if err = json.Unmarshal(file, temp); err != nil {
		GitLog.Println("parse config: ", err)
		os.Exit(1)
	}
	Conf = temp
	token := Conf.Token
	if Conf.Secure {
		key := []byte(oldKey)
		token = encrypt.Decrypt(key, token)
		if err != nil {
			return err
		}
	}
	err = ChangeLogin(Conf.Username, token, newKey)
	return err
}