Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(authentication): allow user to retry input password #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions pkg/tokenycli/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tokenycli
import (
"fmt"
"os"
"time"

"github.com/atotto/clipboard"
"github.com/manifoldco/promptui"
Expand All @@ -14,7 +15,9 @@ import (
)

var (
ppidStr = fmt.Sprintf("%d", os.Getppid())
ppidStr = fmt.Sprintf("%d", os.Getppid())
loginMaxRetries = 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkhang I think this can be clearer. Is number 3 Retries? You mean maxLogin?

failedLogInWaitTime = time.Second
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkhang I think we need to be consistent on Login vs LogIn, also Time is quite unclear

)

type service struct {
Expand Down Expand Up @@ -259,13 +262,23 @@ func (s *service) ensureUser() (bool, error) {
return true, nil
}

err = s.doLogin()
if err != nil {
var isLoggedIn = false
for i := 0; i < loginMaxRetries; i++ {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkhang should we extract login and retrying login logics to another method?

err = s.doLogin()
if errors.Is(err, password.ErrWrongPassword) {
time.Sleep(failedLogInWaitTime)
println("Wrong password, please try again.")
return false, nil
continue
}
return false, err
if err != nil {
return false, err
}
isLoggedIn = true
break
}

if !isLoggedIn {
return false, nil
}

err = s.sessionManager.NewSession(ppidStr)
Expand Down