mirror of
https://github.com/Telecominfraproject/wlan-sdk-mobile-app.git
synced 2025-11-02 03:37:47 +00:00
Merge branch 'main' of https://github.com/stephb9959/ow-self-care
* 'main' of https://github.com/stephb9959/ow-self-care: Reset password requirements validation
This commit is contained in:
@@ -3,6 +3,8 @@ import LocalizedStrings from 'react-native-localization';
|
|||||||
export const strings = new LocalizedStrings({
|
export const strings = new LocalizedStrings({
|
||||||
en: {
|
en: {
|
||||||
errors: {
|
errors: {
|
||||||
|
badEmail: 'Please enter a valid email.',
|
||||||
|
badFormat: 'Please match the requested format.',
|
||||||
credentials: 'Invalid credentials, check username and/or password.',
|
credentials: 'Invalid credentials, check username and/or password.',
|
||||||
emptyFields: 'Please fill in all fields',
|
emptyFields: 'Please fill in all fields',
|
||||||
failedToConnect: 'Failed to connect to server, check connections.',
|
failedToConnect: 'Failed to connect to server, check connections.',
|
||||||
@@ -46,5 +48,12 @@ export const strings = new LocalizedStrings({
|
|||||||
signIn: {
|
signIn: {
|
||||||
description: 'Please sign in to your account.',
|
description: 'Please sign in to your account.',
|
||||||
},
|
},
|
||||||
|
passwordRequirements: {
|
||||||
|
req1: 'Must be at least 8 characters long',
|
||||||
|
req2: 'Must contain 1 uppercase letter',
|
||||||
|
req3: 'Must contain 1 lowercase letter',
|
||||||
|
req4: 'Must contain 1 digit',
|
||||||
|
req5: 'Must contain 1 special character',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,24 +56,35 @@ export default class ForgotPassword extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit = async () => {
|
validateEmail = () => {
|
||||||
this.setState({ loading: true });
|
const re = /\S+@\S+\.\S+/;
|
||||||
try {
|
const valid = re.test(this.state.email);
|
||||||
useStore.getState().clearSession();
|
if (!valid) {
|
||||||
|
Alert.alert(strings.errors.titleForgotPassword, strings.errors.badEmail);
|
||||||
const response = await authenticationApi.getAccessToken(
|
}
|
||||||
{
|
return valid;
|
||||||
userId: this.state.email,
|
}
|
||||||
},
|
|
||||||
undefined,
|
onSubmit = async () => {
|
||||||
true,
|
if (this.validateEmail()) {
|
||||||
);
|
this.setState({ loading: true });
|
||||||
// console.log(JSON.stringify(response.data, null, '\t'));
|
try {
|
||||||
Alert.alert(strings.messages.message, strings.messages.resetEmail);
|
useStore.getState().clearSession();
|
||||||
} catch (error) {
|
|
||||||
handleApiError(strings.errors.titleForgotPassword, error);
|
const response = await authenticationApi.getAccessToken(
|
||||||
|
{
|
||||||
|
userId: this.state.email,
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
// console.log(JSON.stringify(response.data, null, '\t'));
|
||||||
|
Alert.alert(strings.messages.message, strings.messages.resetEmail);
|
||||||
|
} catch (error) {
|
||||||
|
handleApiError(strings.errors.titleForgotPassword, error);
|
||||||
|
}
|
||||||
|
this.setState({ loading: false });
|
||||||
}
|
}
|
||||||
this.setState({ loading: false });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
backToSignin = () => {
|
backToSignin = () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { pageStyle, pageItemStyle } from '../AppStyle';
|
import { pageStyle, pageItemStyle, primaryColor } from "../AppStyle";
|
||||||
import { View, Text, TextInput, Button, Alert, ActivityIndicator } from 'react-native';
|
import { View, Text, TextInput, Button, Alert, ActivityIndicator } from 'react-native';
|
||||||
import { strings } from '../localization/LocalizationStrings';
|
import { strings } from '../localization/LocalizationStrings';
|
||||||
import { authenticationApi, handleApiError } from '../api/apiHandler';
|
import { authenticationApi, handleApiError } from '../api/apiHandler';
|
||||||
@@ -31,18 +31,22 @@ export default function ResetPassword(props) {
|
|||||||
newPassword,
|
newPassword,
|
||||||
);
|
);
|
||||||
console.log(JSON.stringify(response.data, null, '\t'));
|
console.log(JSON.stringify(response.data, null, '\t'));
|
||||||
|
setLoading(false);
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
Alert.alert(strings.messages.message, strings.messages.requestSent);
|
Alert.alert(strings.messages.message, strings.messages.requestSent);
|
||||||
|
props.navigation.replace('SignIn');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleApiError(strings.errors.titleResetPassword, error);
|
handleApiError(strings.errors.titleResetPassword, error);
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkPassword = () => {
|
const checkPassword = () => {
|
||||||
if (newPassword === password) {
|
const valid = validatePassword(newPassword);
|
||||||
|
|
||||||
|
if(newPassword === password) {
|
||||||
Alert.alert(strings.errors.titleResetPassword, strings.errors.samePassword);
|
Alert.alert(strings.errors.titleResetPassword, strings.errors.samePassword);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -50,7 +54,16 @@ export default function ResetPassword(props) {
|
|||||||
Alert.alert(strings.errors.titleResetPassword, strings.errors.mismatchPassword);
|
Alert.alert(strings.errors.titleResetPassword, strings.errors.mismatchPassword);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return newPassword !== password && newPassword === confirmPassword;
|
if(!valid) {
|
||||||
|
Alert.alert(strings.errors.titleResetPassword, strings.errors.badFormat);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return valid && newPassword !== password && newPassword === confirmPassword;
|
||||||
|
};
|
||||||
|
|
||||||
|
const validatePassword = (password) => {
|
||||||
|
const reg = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/;
|
||||||
|
return reg.test(password);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -89,12 +102,26 @@ export default function ResetPassword(props) {
|
|||||||
<View style={pageItemStyle.containerButton}>
|
<View style={pageItemStyle.containerButton}>
|
||||||
<Button
|
<Button
|
||||||
title={strings.buttons.submit}
|
title={strings.buttons.submit}
|
||||||
|
color={primaryColor()}
|
||||||
onPress={onSubmit}
|
onPress={onSubmit}
|
||||||
disabled={loading || !newPassword || !confirmPassword}
|
disabled={loading || !newPassword || !confirmPassword}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={pageItemStyle.containerButton}>
|
<View style={pageItemStyle.containerButton}>
|
||||||
<Button title={strings.buttons.cancel} onPress={onCancel} disabled={loading} />
|
<Button
|
||||||
|
title={strings.buttons.cancel}
|
||||||
|
color={primaryColor()}
|
||||||
|
onPress={onCancel}
|
||||||
|
disabled={loading} />
|
||||||
|
</View>
|
||||||
|
<View style={pageItemStyle.container}>
|
||||||
|
<View>
|
||||||
|
<Text>{`\u2022 ${strings.passwordRequirements.req1}`}</Text>
|
||||||
|
<Text>{`\u2022 ${strings.passwordRequirements.req2}`}</Text>
|
||||||
|
<Text>{`\u2022 ${strings.passwordRequirements.req3}`}</Text>
|
||||||
|
<Text>{`\u2022 ${strings.passwordRequirements.req4}`}</Text>
|
||||||
|
<Text>{`\u2022 ${strings.passwordRequirements.req5}`}</Text>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user