password flow improvements (#2730)
* add button to skip sending reset code * add validation to reset code * comments * update test id * consistency sneak in - everything capitalized * add change password button to settings * create a modal for password change * change password modal * remove unused styles * more improvements * improve layout * change done button color * add already have a code to modal * remove unused prop * icons, auto add dash * cleanup * better appearance on android * Remove log * Improve error messages and add specificity to function names --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
This commit is contained in:
parent
b9e00afdb1
commit
a9ab13e5a9
8 changed files with 448 additions and 7 deletions
|
@ -195,6 +195,29 @@ export const ForgotPasswordForm = ({
|
|||
</Text>
|
||||
) : undefined}
|
||||
</View>
|
||||
<View
|
||||
style={[
|
||||
s.flexRow,
|
||||
s.alignCenter,
|
||||
s.mt20,
|
||||
s.mb20,
|
||||
pal.border,
|
||||
s.borderBottom1,
|
||||
{alignSelf: 'center', width: '90%'},
|
||||
]}
|
||||
/>
|
||||
<View style={[s.flexRow, s.justifyCenter]}>
|
||||
<TouchableOpacity
|
||||
testID="skipSendEmailButton"
|
||||
onPress={onEmailSent}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={_(msg`Go to next`)}
|
||||
accessibilityHint={_(msg`Navigates to the next screen`)}>
|
||||
<Text type="xl" style={[pal.link, s.pr5]}>
|
||||
<Trans>Already have a code?</Trans>
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
)
|
||||
|
|
|
@ -14,6 +14,7 @@ import {isNetworkError} from 'lib/strings/errors'
|
|||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useTheme} from 'lib/ThemeContext'
|
||||
import {cleanError} from 'lib/strings/errors'
|
||||
import {checkAndFormatResetCode} from 'lib/strings/password'
|
||||
import {logger} from '#/logger'
|
||||
import {styles} from './styles'
|
||||
import {Trans, msg} from '@lingui/macro'
|
||||
|
@ -46,14 +47,26 @@ export const SetNewPasswordForm = ({
|
|||
const [password, setPassword] = useState<string>('')
|
||||
|
||||
const onPressNext = async () => {
|
||||
// Check that the code is correct. We do this again just incase the user enters the code after their pw and we
|
||||
// don't get to call onBlur first
|
||||
const formattedCode = checkAndFormatResetCode(resetCode)
|
||||
// TODO Better password strength check
|
||||
if (!formattedCode || !password) {
|
||||
setError(
|
||||
_(
|
||||
msg`You have entered an invalid code. It should look like XXXXX-XXXXX.`,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
setError('')
|
||||
setIsProcessing(true)
|
||||
|
||||
try {
|
||||
const agent = new BskyAgent({service: serviceUrl})
|
||||
const token = resetCode.replace(/\s/g, '')
|
||||
await agent.com.atproto.server.resetPassword({
|
||||
token,
|
||||
token: formattedCode,
|
||||
password,
|
||||
})
|
||||
onPasswordSet()
|
||||
|
@ -71,6 +84,19 @@ export const SetNewPasswordForm = ({
|
|||
}
|
||||
}
|
||||
|
||||
const onBlur = () => {
|
||||
const formattedCode = checkAndFormatResetCode(resetCode)
|
||||
if (!formattedCode) {
|
||||
setError(
|
||||
_(
|
||||
msg`You have entered an invalid code. It should look like XXXXX-XXXXX.`,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
setResetCode(formattedCode)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<View>
|
||||
|
@ -100,9 +126,11 @@ export const SetNewPasswordForm = ({
|
|||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardAppearance={theme.colorScheme}
|
||||
autoFocus
|
||||
autoComplete="off"
|
||||
value={resetCode}
|
||||
onChangeText={setResetCode}
|
||||
onFocus={() => setError('')}
|
||||
onBlur={onBlur}
|
||||
editable={!isProcessing}
|
||||
accessible={true}
|
||||
accessibilityLabel={_(msg`Reset code`)}
|
||||
|
@ -123,6 +151,7 @@ export const SetNewPasswordForm = ({
|
|||
placeholderTextColor={pal.colors.textLight}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
autoComplete="new-password"
|
||||
keyboardAppearance={theme.colorScheme}
|
||||
secureTextEntry
|
||||
value={password}
|
||||
|
@ -160,6 +189,7 @@ export const SetNewPasswordForm = ({
|
|||
) : (
|
||||
<TouchableOpacity
|
||||
testID="setNewPasswordButton"
|
||||
// Check the code before running the callback
|
||||
onPress={onPressNext}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={_(msg`Go to next`)}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue