Exemple #1
0
func (u *gtkUI) loadConfig(configFile string) {
	u.config.WhenLoaded(func(c *config.ApplicationConfig) {
		u.configLoaded(c)
	})

	ok := false
	var conf *config.ApplicationConfig
	var err error
	for !ok {
		conf, ok, err = config.LoadOrCreate(configFile, u.keySupplier)
		if !ok {
			log.Printf("couldn't open encrypted file - either the user didn't supply a password, or the password was incorrect: %v", err)
			u.keySupplier.Invalidate()
			u.keySupplier.LastAttemptFailed()
		}
	}

	// We assign config here, AFTER the return - so that a nil config means we are in a state of incorrectness and shouldn't do stuff.
	// We never check, since a panic here is a serious programming error
	u.config = conf

	if err != nil {
		log.Printf(err.Error())
		doInUIThread(u.initialSetupWindow)
		return
	}
	if u.config.UpdateToLatestVersion() {
		u.saveConfigOnlyInternal()
	}
}
Exemple #2
0
Fichier : ui.go Projet : 0x27/coyim
func (u *gtkUI) loadConfig(configFile string) {
	u.config.WhenLoaded(func(c *config.ApplicationConfig) {
		u.configLoaded(c)
	})

	config, ok, err := config.LoadOrCreate(configFile, u.keySupplier)

	if !ok {
		u.keySupplier.Invalidate()
		u.loadConfig(configFile)
		// TODO: tell the user we couldn't open the encrypted file
		log.Printf("couldn't open encrypted file - either the user didn't supply a password, or the password was incorrect")
		return
	}

	// We assign config here, AFTER the return - so that a nil config means we are in a state of incorrectness and shouldn't do stuff.
	// TODO: we never check if config is nil. Is it intentional to have panics due nil pointer?
	u.config = config

	if err != nil {
		log.Printf(err.Error())
		doInUIThread(u.initialSetupWindow)
		return
	}
}
Exemple #3
0
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
}