Skip to content

Commit

Permalink
Fixed captcha validity for SignUp and retrieve password
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixH committed Jan 14, 2022
1 parent 496ee8b commit 5a70506
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/FormStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
marginBottom: '10@s',
backgroundColor: commonColor.buttonBg
},
buttonDisabled: {
opacity: 0.4
},
buttonText: {
width: '100%',
textAlign: 'center',
Expand Down
9 changes: 8 additions & 1 deletion src/config/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { EndpointCloud } from '../types/Tenant';

export default class Configuration {
public static readonly AWS_REST_ENDPOINT_PROD = 'https://rest.e-mobility-group.com';
public static readonly AWS_REST_ENDPOINT_QA = 'https://qa-e-mobility-group.com';


public static readonly SCP_CAPTCHA_BASE_URL = 'https://evse.cfapps.eu10.hana.ondemand.com';
public static readonly SCP_CAPTCHA_SITE_KEY = '6Lcmr6EUAAAAAIyn3LasUzk-0MpH2R1COXFYsxNw';

public static readonly DEFAULT_ENDPOINT_CLOUD_ID = 'aws';
Expand All @@ -23,7 +24,13 @@ export default class Configuration {
id: '10.0.2.2:8080',
name: 'android-local:8080',
endpoint: 'http://10.0.2.2:8080'
},
{
id: 'kubernetes',
name: 'QA',
endpoint: Configuration.AWS_REST_ENDPOINT_QA
}

];

public static readonly DEVELOPMENT_ENDPOINT_CLOUDS: EndpointCloud[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/provider/CentralServerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import SecurityProvider from './SecurityProvider';
export default class CentralServerProvider {
private axiosInstance: AxiosInstance;
private debug = false;
private captchaBaseUrl: string = Configuration.SCP_CAPTCHA_BASE_URL;
private captchaBaseUrl: string = Configuration.AWS_REST_ENDPOINT_PROD;
private captchaSiteKey: string = Configuration.SCP_CAPTCHA_SITE_KEY;

// Paste the token below
Expand Down
12 changes: 7 additions & 5 deletions src/screens/auth/retrieve-password/RetrievePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ export default class RetrievePassword extends BaseScreen<Props, State> {

public retrievePassword = async () => {
// Check field
const formIsValid = Utils.validateInput(this, this.formValidationDef);
if (formIsValid) {
const { tenantSubDomain, email, captcha } = this.state;
const { tenantSubDomain, email, captcha } = this.state;
const formIsValid = Utils.validateInput(this, this.formValidationDef)
// Force captcha regeneration for next signUp click
this.setState({captcha: null});
if (formIsValid && captcha) {
try {
this.setState({ loading: true });
// Login
Expand Down Expand Up @@ -169,7 +171,7 @@ export default class RetrievePassword extends BaseScreen<Props, State> {
{errorMessage}
</Text>
))}
{loading || !captcha ? (
{loading ? (
<Spinner style={formStyle.spinner} color="grey" />
) : (
<Button primary block style={formStyle.button} onPress={async () => this.retrievePassword()}>
Expand All @@ -180,7 +182,7 @@ export default class RetrievePassword extends BaseScreen<Props, State> {
)}
</Form>
</KeyboardAvoidingView>
{captchaSiteKey && captchaBaseUrl && (
{captchaSiteKey && captchaBaseUrl && !captcha && (
<ReactNativeRecaptchaV3
action="ResetPassword"
onHandleToken={this.recaptchaResponseToken}
Expand Down
16 changes: 10 additions & 6 deletions src/screens/auth/sign-up/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ export default class SignUp extends BaseScreen<Props, State> {

public signUp = async () => {
// Check field
const { tenantSubDomain, name, firstName, email, password, eula, captcha } = this.state
const formIsValid = Utils.validateInput(this, this.formValidationDef);
if (formIsValid) {
const { tenantSubDomain, name, firstName, email, password, eula, captcha } = this.state;
// Force captcha regeneration for next signUp click
this.setState({captcha: null});
if (formIsValid && captcha && eula) {
this.setState({loading: true})
try {
// Loading
this.setState({ loading: true });
Expand Down Expand Up @@ -212,6 +215,7 @@ export default class SignUp extends BaseScreen<Props, State> {
}
}
}
this.setState({loading: false})
};

public onBack(): boolean {
Expand Down Expand Up @@ -370,7 +374,7 @@ export default class SignUp extends BaseScreen<Props, State> {
</Text>
))}
<View style={formStyle.formCheckboxContainer}>
<CheckBox style={formStyle.checkbox} checked={eula} onPress={() => this.setState({ eula: !eula, captcha: null })} />
<CheckBox style={formStyle.checkbox} checked={eula} onPress={() => this.setState({ eula: !eula})} />
<Text style={formStyle.checkboxText}>
{I18n.t('authentication.acceptEula')}
<Text onPress={() => navigation.navigate('Eula')} style={style.eulaLink}>
Expand All @@ -384,18 +388,18 @@ export default class SignUp extends BaseScreen<Props, State> {
{errorMessage}
</Text>
))}
{loading || (!captcha && this.state.eula) ? (
{loading ? (
<Spinner style={formStyle.spinner} color="grey" />
) : (
<Button primary block style={formStyle.button} onPress={async () => this.signUp()}>
<Button disabled={!eula} primary block style={[formStyle.button, (!eula || !captcha) && formStyle.buttonDisabled]} onPress={async () => this.signUp()}>
<Text style={formStyle.buttonText} uppercase={false}>
{I18n.t('authentication.signUp')}
</Text>
</Button>
)}
</Form>
</KeyboardAvoidingView>
{this.state.eula && captchaSiteKey && captchaBaseUrl && (
{!captcha && captchaSiteKey && captchaBaseUrl && (
<ReactNativeRecaptchaV3
action="RegisterUser"
onHandleToken={this.recaptchaResponseToken}
Expand Down

0 comments on commit 5a70506

Please sign in to comment.