Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
clean up login
Browse files Browse the repository at this point in the history
  • Loading branch information
SoMuchForSubtlety committed Aug 30, 2021
1 parent ddef349 commit aef73a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
16 changes: 6 additions & 10 deletions internal/secret/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,27 @@ type SecretStore struct {
ring keyring.Keyring
}

func (s *SecretStore) LoadCredentials() (string, string, string, error) {
func (s *SecretStore) LoadCredentials() (string, string, error) {
if s.ring == nil {
err := s.openRing()
if err != nil {
return "", "", "", err
return "", "", err
}
}

if s.ring == nil {
return "", "", "", errors.New("No keyring configured")
return "", "", errors.New("No keyring configured")
}
username, err := s.ring.Get("username")
if err != nil {
return "", "", "", fmt.Errorf("Could not get username: %w", err)
return "", "", fmt.Errorf("Could not get username: %w", err)
}

password, err := s.ring.Get("password")
if err != nil {
return "", "", "", fmt.Errorf("Could not get password: %w", err)
return "", "", fmt.Errorf("Could not get password: %w", err)
}
token, err := s.ring.Get("skylarkToken")
if err != nil {
return "", "", "", fmt.Errorf("Could not get auth token: %w", err)
}
return string(username.Data), string(password.Data), string(token.Data), nil
return string(username.Data), string(password.Data), nil
}

func (s *SecretStore) SaveCredentials(username, password, authtoken string) error {
Expand Down
12 changes: 6 additions & 6 deletions internal/ui/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,26 +177,26 @@ func (s *UIState) logout() {
}

func (s *UIState) loginWithStoredCredentials() error {
username, password, token, err := s.secret.LoadCredentials()
username, password, err := s.secret.LoadCredentials()
if err != nil {
return err
}
return s.login(username, password, token)
return s.login(username, password)
}

func (s *UIState) login(username, pw, token string) error {
func (s *UIState) login(username, pw string) error {
// todo save auth token in credential store
err := s.v2.Authenticate(username, pw, s.logger)
return err
}

func (s *UIState) initUIWithForm() {
username, pw, _, _ := s.secret.LoadCredentials()
username, pw, _ := s.secret.LoadCredentials()
form := tview.NewForm().
AddInputField("email", username, 30, nil, func(text string) { username = text }).
AddPasswordField("password", "", 30, '*', func(text string) { pw = text }).
AddButton("test", func() {
err := s.login(username, pw, "")
err := s.login(username, pw)
if err == nil {
s.logger.Info("credentials accepted")
} else {
Expand Down Expand Up @@ -245,7 +245,7 @@ func (s *UIState) initUI() {
}

func (s *UIState) closeForm(username, pw string) {
err := s.login(username, pw, "")
err := s.login(username, pw)
if err != nil {
s.logger.Error(err)
} else {
Expand Down

0 comments on commit aef73a9

Please sign in to comment.