password validate

This commit is contained in:
Maria Sanchez 2022-08-30 21:22:41 -06:00
parent 73bd3c5adb
commit 78bad074c7
2 changed files with 35 additions and 11 deletions

View File

@ -9,6 +9,7 @@ import { UserContext } from "../context/UserContext";
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs'; import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import { stringMd5 } from 'react-native-quick-md5'; import { stringMd5 } from 'react-native-quick-md5';
const { Navigator, Screen } = createMaterialTopTabNavigator(); const { Navigator, Screen } = createMaterialTopTabNavigator();
export default function Profile({ navigation }) { export default function Profile({ navigation }) {
@ -23,6 +24,7 @@ export default function Profile({ navigation }) {
const userData = useContext(UserContext) const userData = useContext(UserContext)
const id = userData.user._id; const id = userData.user._id;
const decode = userData.Password; const decode = userData.Password;
const [error, setError] = useState({})
console.log(userData.user); console.log(userData.user);
@ -32,11 +34,15 @@ export default function Profile({ navigation }) {
console.log(dpassword); console.log(dpassword);
console.log(userData.password); console.log(userData.user.password);
if (userData.password == dpassword) { if (userData.user.password == dpassword) {
console.log(true); console.log(true);
}else{ }else{
console.log(false); console.log(false);
setError({ ...error,
password: 'La contraseña no coincide con la actual'
});
} }
} }
@ -115,21 +121,26 @@ export default function Profile({ navigation }) {
<VStack space={3} mt="5"> <VStack space={3} mt="5">
<FormControl> <FormControl>
<FormControl.Label>Contraseña actual</FormControl.Label> <FormControl.Label>Contraseña actual</FormControl.Label>
<TextInput style={styles.input} type="password" defaultValue="" onChangeText={(value) => onHandleChangePassword(value) }/> <TextInput style={'password' in error ? styles.errorMessage : styles.input} type="password" defaultValue="" onChangeText={(value) => onHandleChangePassword(value) }/>
</FormControl> </FormControl>
<FormControl> <FormControl>
<FormControl.Label>Nueva Contraseña</FormControl.Label> <FormControl.Label>Nueva Contraseña</FormControl.Label>
<TextInput style={styles.input} type="password" defaultValue="" onChangeText={(value) => setPassword(value) }/> <TextInput editable={!error} style={styles.input} type="password" defaultValue="" onChangeText={(value) => setPassword(value) } />
</FormControl> </FormControl>
<FormControl> <FormControl>
<FormControl.Label>Confirmar nueva contraseña</FormControl.Label> <FormControl.Label>Confirmar nueva contraseña</FormControl.Label>
<TextInput style={styles.input} type="password" defaultValue="" onChangeText={(value) => setPassword(value) }/> <TextInput editable={!error} style={styles.input} type="password" defaultValue="" onChangeText={(value) => setPassword(value) }/>
</FormControl> </FormControl>
<Button mt="2" backgroundColor="orange.300" onPress={() => updateInfo()}> <Button mt="2" backgroundColor="orange.300" onPress={() => updateInfo()} disabled={error}>
Actualizar contraseña Actualizar contraseña
</Button> </Button>
{/* {'password' in error && <FormControl.ErrorMessage _text={{
fontSize: 'xs'
}}>La contraseña no coincide con la actual</FormControl.ErrorMessage> } */}
</VStack> </VStack>
</Box> </Box>
@ -202,18 +213,29 @@ export default function Profile({ navigation }) {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
input: { input: {
height: 10, height: 35,
margin: 3, margin: 3,
borderWidth: 0.5, borderWidth: 0.5,
padding: 5, padding: 5,
flex: 1, flex: 1,
paddingTop: 9, paddingTop: 9,
paddingRight: 19, paddingRight: 19,
paddingBottom: 20,
paddingLeft: 0, paddingLeft: 0,
marginTop: 6, marginTop: 6,
marginBottom: 6,
borderRadius: 4 borderRadius: 4
},
errorMessage: {
height: 35,
margin: 3,
borderWidth: 0.5,
padding: 5,
flex: 1,
paddingTop: 9,
paddingRight: 19,
paddingLeft: 0,
marginTop: 6,
borderRadius: 4,
borderColor: '#be123c'
} }
}) })

View File

@ -14,7 +14,8 @@
"android": "expo start --android", "android": "expo start --android",
"ios": "expo start --ios", "ios": "expo start --ios",
"web": "expo start --web", "web": "expo start --web",
"eject": "expo eject" "eject": "expo eject",
"test" : "jest"
}, },
"dependencies": { "dependencies": {
"@react-native-community/datetimepicker": "4.0.0", "@react-native-community/datetimepicker": "4.0.0",
@ -46,7 +47,8 @@
"universal-cookie": "^4.0.4" "universal-cookie": "^4.0.4"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.12.9" "@babel/core": "^7.12.9",
"jest": "^29.0.1"
}, },
"bugs": { "bugs": {
"url": "https://github.com/GeekyAnts/nativebase-templates/issues" "url": "https://github.com/GeekyAnts/nativebase-templates/issues"