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

Handle wait on the password login scene #204

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fixed: When password login is locked out for some time period, show the time instead of "Invalid password".

## 3.18.0 (2024-08-22)

- changed: "<No Username>" changed to: "Guest Account ([last 3 loginId characters])"
Expand Down
1 change: 1 addition & 0 deletions src/common/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"password_recovery": "Password Recovery",
"password_requirements": "Password Requirements",
"password": "Password",
"password_wait_1s": "Please try again in %1$s",
"pin_changed": "PIN Changed",
"pin_desc_alt": "Your PIN is a 4 digit code used to quickly log back into your account.",
"pin_desc": "Your PIN is a 4 digit code used to quickly log back into your account.\n\nPIN login is only usable on a device after first login with password.",
Expand Down
10 changes: 9 additions & 1 deletion src/components/scenes/PasswordLoginScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { lstrings } from '../../common/locales/strings'
import { useHandler } from '../../hooks/useHandler'
import { useImports } from '../../hooks/useImports'
import { LoginUserInfo, useLocalUsers } from '../../hooks/useLocalUsers'
import { formatWait } from '../../locales/intl'
import { Branding } from '../../types/Branding'
import { useDispatch } from '../../types/ReduxTypes'
import { SceneProps } from '../../types/routerTypes'
Expand Down Expand Up @@ -232,7 +233,14 @@ export const PasswordLoginScene = (props: Props) => {

const passwordError = asMaybePasswordError(error)
if (passwordError != null) {
setPasswordErrorMessage(lstrings.invalid_password)
const { wait } = passwordError
if (wait != null) {
setPasswordErrorMessage(
sprintf(lstrings.password_wait_1s, formatWait(wait))
)
} else {
setPasswordErrorMessage(lstrings.invalid_password)
}
return
}

Expand Down
10 changes: 10 additions & 0 deletions src/locales/intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ export function formatTime(date: Date): string {
return format(date, 'h:mm bb')
}

/**
* Formats a time duration, such as 1.5 minutes or 2 hours
*/
export function formatWait(seconds: number): string {
if (seconds > 90 * 60) return (seconds / (60 * 60)).toFixed(1) + 'h'
if (seconds > 90) return (seconds / 60).toFixed(1) + 'm'
if (seconds > 1) return seconds.toFixed(1) + 's'
return (1000 * seconds).toFixed(1) + 'ms'
}

/**
* Returns 'h:mm am/pm, date' string depending on locale.
*/
Expand Down
Loading