예제 #1
0
파일: ui.go 프로젝트: rosatolen/coyim
func (c *cliUI) loadConfig(configFile string) error {
	accounts, ok, err := config.LoadOrCreate(configFile, config.FunctionKeySupplier(c.getMasterPassword))
	if !ok {
		c.alert("Couldn't open encrypted file - did you enter your password correctly?")
		return errors.New("couldn't open encrypted file - did you supply the wrong password?")
	}
	if err != nil {
		c.alert(err.Error())
		acc, e := accounts.AddNewAccount()
		if e != nil {
			return e
		}
		if !c.enroll(accounts, acc) {
			return errors.New("asked to quit")
		}
	}

	account := findAccount(config.AccountFlag, accounts.Accounts)

	var password string
	if len(account.Password) == 0 {
		var err error

		password, err = c.term.ReadPassword(
			fmt.Sprintf("Password for %s (will not be saved to disk): ", account.Account),
		)
		if err != nil {
			c.alert(err.Error())
			return err
		}
	} else {
		password = account.Password
	}

	logger := &lineLogger{c.term, c.termControl, nil}

	//TODO: call session.ConnectAndRegister() in this case
	//var registerCallback xmpp.FormCallback
	//if *config.CreateAccount {
	//	registerCallback = c.RegisterCallback
	//}

	c.session = c.sessionFactory(accounts, account, c.dialerFactory)
	c.session.SetSessionEventHandler(c)
	c.session.Subscribe(c.events)

	c.session.SetConnectionLogger(logger)
	// TODO: this nil is incorrect and will cause failures when trying to use it.
	if err := c.session.Connect(password, c.verifier()); err != nil {
		c.alert(err.Error())
		return err
	}

	return nil
}
예제 #2
0
파일: ui.go 프로젝트: VKCheung/coyim
func (c *cliUI) SaveConf() {
	c.session.Config().Save(config.FunctionKeySupplier(c.getMasterPassword))
}