-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package tokenycli | |
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/atotto/clipboard" | ||
"github.com/manifoldco/promptui" | ||
|
@@ -14,7 +15,9 @@ import ( | |
) | ||
|
||
var ( | ||
ppidStr = fmt.Sprintf("%d", os.Getppid()) | ||
ppidStr = fmt.Sprintf("%d", os.Getppid()) | ||
loginMaxRetries = 3 | ||
failedLogInWaitTime = time.Second | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nkhang I think we need to be consistent on |
||
) | ||
|
||
type service struct { | ||
|
@@ -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++ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment.
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 meanmaxLogin
?