Skip to content

Commit

Permalink
Add showTerms option (#1485)
Browse files Browse the repository at this point in the history
Add `showTerms` option to show/hide terms string in the signup page
  • Loading branch information
luisrudge authored Nov 9, 2018
1 parent ebaf498 commit 41b922a
Show file tree
Hide file tree
Showing 38 changed files with 147 additions and 76 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ var options = {
- **initialScreen {String}**: Name of the screen that will be shown when the widget is opened. Valid values are `"login"`, `"signUp"`, and `"forgotPassword"`. If this option is left unspecified, the widget will pick the first screen that is available from the previous list. If you set `initialScreen` to `"forgotPassword"` we recommend that you set `allowLogin` to `"false"`, otherwise a back button will be shown in the forgot password screen and it might not be clear to the user where that back button will take them.
- **loginAfterSignUp {Boolean}**: Determines whether or not the user will be automatically signed in after a successful sign up. Defaults to `true`.
- **forgotPasswordLink {String}**: URL for a page that allows the user to reset her password. When set to a non-empty string, the user will be linked to the provided URL when clicking the _"Don't remember your password?"_ link in the _login screen_.
- **showTerms {Boolean}**: When set to `true` displays the `languageDictionary.signUpTerms` string. Defaults to `true`.
- **mustAcceptTerms {Boolean}**: When set to `true` displays a checkbox input along with the terms and conditions that must be checked before signing up. The terms and conditions can be specified via the `languageDictionary` option, see the example below. Defaults to `false`.
- **prefill {Object}**: Allows you to set the initial value for the _email_ and/or _username_ inputs, e.g. `{prefill: {email: "[email protected]", username: "someone"}}`. When omitted no initial value will be provided.
- **signUpLink {String}**: URL for a page that allows the user to sign up. When set to a non-empty string, the user will be linked to the provided URL when clicking the _sign up_ tab in the _login screen_.
Expand Down
17 changes: 11 additions & 6 deletions scripts/complete-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ const restoreWildCards = str =>
str.replace(/__( d|d |d)__/gi, '%d').replace(/__( s|s |s)__/gi, '%s');

const processLanguage = async lang => {
console.log(`translating: ${lang}`);
const langDictionary = require('../lib/i18n/' + lang).default;
await processNode(enDictionary, langDictionary, lang);
const communityAlert = `
try {
console.log(`translating: ${lang}`);
const langDictionary = require('../lib/i18n/' + lang).default;
await processNode(enDictionary, langDictionary, lang);
const communityAlert = `
// This file was automatically translated.
// Feel free to submit a PR if you find a more accurate translation.
`;
const jsContent = `
const jsContent = `
${isSupportedByAuth0(lang) ? '' : communityAlert}
export default ${JSON.stringify(langDictionary, null, 2)};
`;
await writeFileAsync(`src/i18n/${lang}.js`, jsContent);
await writeFileAsync(`src/i18n/${lang}.js`, jsContent);
} catch (error) {
console.log(`Error translating ${lang}.`);
console.log(error.message);
}
};

const processNode = async (enNode, langNode, lang) => {
Expand Down
33 changes: 32 additions & 1 deletion src/__tests__/engine/classic/sign_up_screen.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describe('SignUpScreen', () => {
},
termsAccepted: () => true,
hasScreen: () => false,
mustAcceptTerms: () => false
mustAcceptTerms: () => false,
showTerms: () => true
}));

jest.mock('connection/database/actions', () => ({
Expand Down Expand Up @@ -135,4 +136,34 @@ describe('SignUpScreen', () => {
expect(mock.calls.length).toBe(1);
});
});
describe('renders SignupTerms', () => {
it('when showTerms() && `terms` are truthy', () => {
const screen = getScreen();
const terms = screen.renderTerms('m', true);
expect(terms).not.toBe(null);
});
it('with a checkbox when mustAcceptTerms() is true', () => {
require('connection/database/index').mustAcceptTerms = () => true;
const screen = getScreen();
const terms = screen.renderTerms('m', true);
expect(terms.props.showCheckbox).toBe(true);
});
it('without a checkbox when mustAcceptTerms() is true', () => {
require('connection/database/index').mustAcceptTerms = () => false;
const screen = getScreen();
const terms = screen.renderTerms('m', true);
expect(terms.props.showCheckbox).toBe(false);
});
});
it('do not render SignupTerms when showTerms() is false', () => {
require('connection/database/index').showTerms = () => false;
const screen = getScreen();
const terms = screen.renderTerms('m', true);
expect(terms).toBe(null);
});
it('do not render SignupTerms when `terms` is falsy', () => {
const screen = getScreen();
const terms = screen.renderTerms('m', undefined);
expect(terms).toBe(null);
});
});
10 changes: 10 additions & 0 deletions src/connection/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function processDatabaseOptions(opts) {
forgotPasswordLink,
loginAfterSignUp,
mustAcceptTerms,
showTerms,
signUpLink,
usernameStyle
} = opts;
Expand All @@ -86,6 +87,10 @@ function processDatabaseOptions(opts) {
mustAcceptTerms = undefined;
}

if (!assertMaybeBoolean(opts, 'showTerms')) {
showTerms = true;
}

if (!assertMaybeArray(opts, 'additionalSignUpFields')) {
additionalSignUpFields = undefined;
} else if (additionalSignUpFields) {
Expand Down Expand Up @@ -210,6 +215,7 @@ function processDatabaseOptions(opts) {
initialScreen,
loginAfterSignUp,
mustAcceptTerms,
showTerms,
screens,
signUpLink,
usernameStyle
Expand Down Expand Up @@ -397,6 +403,10 @@ export function additionalSignUpFields(m) {
return get(m, 'additionalSignUpFields', List());
}

export function showTerms(m) {
return get(m, 'showTerms', true);
}

export function mustAcceptTerms(m) {
return get(m, 'mustAcceptTerms', false);
}
Expand Down
4 changes: 2 additions & 2 deletions src/connection/database/sign_up_terms.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';

const SignUpTerms = ({ checkHandler, checked, children }) => {
const SignUpTerms = ({ checkHandler, checked, children, showCheckbox }) => {
return checkHandler ? (
<span className="auth0-lock-sign-up-terms-agreement">
<label>
<input type="checkbox" onChange={checkHandler} checked={checked} />
{showCheckbox && <input type="checkbox" onChange={checkHandler} checked={checked} />}
{children}
</label>
</span>
Expand Down
15 changes: 12 additions & 3 deletions src/engine/classic/sign_up_screen.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import Screen from '../../core/screen';

import { hasScreen, mustAcceptTerms, termsAccepted } from '../../connection/database/index';
import {
hasScreen,
showTerms,
mustAcceptTerms,
termsAccepted
} from '../../connection/database/index';
import { signUp, toggleTermsAcceptance } from '../../connection/database/actions';
import { hasOnlyClassicConnections, isSSOEnabled, useBigSocialButtons } from '../classic';
import { renderSignedInConfirmation } from '../../core/signed_in_confirmation';
Expand Down Expand Up @@ -122,8 +127,12 @@ export default class SignUp extends Screen {

renderTerms(m, terms) {
const checkHandler = mustAcceptTerms(m) ? () => toggleTermsAcceptance(l.id(m)) : undefined;
return terms || mustAcceptTerms(m) ? (
<SignUpTerms checkHandler={checkHandler} checked={termsAccepted(m)}>
return terms && showTerms(m) ? (
<SignUpTerms
showCheckbox={mustAcceptTerms(m)}
checkHandler={checkHandler}
checked={termsAccepted(m)}
>
{terms}
</SignUpTerms>
) : null;
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/af.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default {
signUpTitle: 'Registreer',
signUpLabel: 'Registreer',
signUpSubmitLabel: 'Registreer',
signUpTerms: '',
signUpWithLabel: 'Registreer %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -120,5 +119,6 @@ export default {
mfaLoginInstructions: 'Vul asseblief die kode in wat deur jou toestel geskep is.',
mfaSubmitLabel: 'Gaan voort',
mfaCodeErrorHint: 'Gebruik %d nommers',
showPassword: 'Wys wagwoord'
showPassword: 'Wys wagwoord',
signUpTerms: 'Deur u in te teken, stem u in tot ons diensbepalings en privaatheidsbeleid.'
};
5 changes: 3 additions & 2 deletions src/i18n/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export default {
signUpTitle: 'Registre',
signUpLabel: 'Registre',
signUpSubmitLabel: "Registra'm",
signUpTerms: '',
signUpWithLabel: 'Registreu-vos amb %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -128,5 +127,7 @@ export default {
mfaLoginInstructions: 'Indiqueu el codi de verificació generat per la seva aplicació de mòbil.',
mfaSubmitLabel: 'Inicia sessió',
mfaCodeErrorHint: 'Utilitzeu %d xifres',
showPassword: 'Ensenya la contrasenya'
showPassword: 'Ensenya la contrasenya',
signUpTerms:
"En inscriure's, accepteu les nostres condicions de servei i la nostra política de privadesa."
};
5 changes: 3 additions & 2 deletions src/i18n/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export default {
signUpTitle: 'Registrace',
signUpLabel: 'Registrace',
signUpSubmitLabel: 'Registrovat',
signUpTerms: '',
signUpWithLabel: 'Registrovat se s %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -124,5 +123,7 @@ export default {
mfaLoginTitle: 'Dvoufázové ověření',
mfaLoginInstructions: 'Prosím zadej ověřovací kód vygenerovaný mobilní aplikací.',
mfaSubmitLabel: 'Přihlásit',
mfaCodeErrorHint: 'Použijte %d číslic'
mfaCodeErrorHint: 'Použijte %d číslic',
signUpTerms:
'Tím, že se zaregistrujete, souhlasíte s našimi smluvními podmínkami a zásadami ochrany osobních údajů.'
};
4 changes: 2 additions & 2 deletions src/i18n/da.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export default {
sentLabel: 'Sendt!',
signUpLabel: 'Opret dig',
signUpSubmitLabel: 'Opret dig',
signUpTerms: '',
signUpWithLabel: 'Opret dig med %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -126,5 +125,6 @@ export default {
mfaLoginInstructions: 'Indtast venligst bekræftelseskoden genereret af din mobilapplikation.',
mfaSubmitLabel: 'Log på',
mfaCodeErrorHint: 'Brug %d tal',
showPassword: 'Vis adgangskode'
showPassword: 'Vis adgangskode',
signUpTerms: 'Ved at tilmelde dig accepterer du vores servicevilkår og privatlivspolitik.'
};
3 changes: 2 additions & 1 deletion src/i18n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export default {
signUpTitle: 'Anmelden',
signUpLabel: 'Registrieren',
signUpSubmitLabel: 'Registrieren',
signUpTerms: '',
signUpWithLabel: 'Registrieren mit %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -129,4 +128,6 @@ export default {
'Bitte geben Sie den Bestätigungscode ein, der von Ihrer mobilen Anwendung generiert wurde.',
mfaSubmitLabel: 'Anmelden',
mfaCodeErrorHint: 'Verwenden %d Zahlen',
signUpTerms:
'Mit der Anmeldung stimmen Sie unseren Nutzungsbedingungen und Datenschutzbestimmungen zu.'
};
2 changes: 1 addition & 1 deletion src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default {
signUpTitle: 'Sign Up',
signUpLabel: 'Sign Up',
signUpSubmitLabel: 'Sign Up',
signUpTerms: '',
signUpTerms: 'By signing up, you agree to our terms of service and privacy policy.',
signUpWithLabel: 'Sign up with %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export default {
signUpTitle: 'Registrarse',
signUpLabel: 'Registrarse',
signUpSubmitLabel: 'Registrarse',
signUpTerms: '',
signUpWithLabel: 'Registrarse con %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -123,5 +122,6 @@ export default {
'Por favor ingrese el código de verificación generado por su aplicación móvil.',
mfaSubmitLabel: 'Enviar',
mfaCodeErrorHint: '%d números',
showPassword: 'Mostrar contraseña'
showPassword: 'Mostrar contraseña',
signUpTerms: 'Al suscribirse usted acepta nuestros términos de servicio y política de privacidad.'
};
4 changes: 2 additions & 2 deletions src/i18n/et.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export default {
signUpTitle: 'Registreeri',
signUpLabel: 'Registreeri',
signUpSubmitLabel: 'Registreeri',
signUpTerms: '',
signUpWithLabel: 'Registreeri kasutades %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -125,5 +124,6 @@ export default {
mfaLoginTitle: '2-Sammuline Tuvastamine',
mfaLoginInstructions: 'Palun sisesta tuvastuskood mille genereeris su mobiilirakendus',
mfaSubmitLabel: 'Logi sisse',
mfaCodeErrorHint: 'Kasuta %d numbrit'
mfaCodeErrorHint: 'Kasuta %d numbrit',
signUpTerms: 'Registreerudes nõustute meie teenusetingimustega ja privaatsuspoliitikaga.'
};
4 changes: 2 additions & 2 deletions src/i18n/fa.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export default {
sentLabel: 'ارسال شد!',
signUpLabel: 'ثبت نام',
signUpSubmitLabel: 'ثبت نام',
signUpTerms: '',
signUpWithLabel: 'ورود با %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -123,5 +122,6 @@ export default {
mfaCodeErrorHint: 'از %d عدد استفاده کنید',
forgotPasswordTitle: 'تنظیم مجدد کلمه ورود',
signUpTitle: 'ثبت نام',
showPassword: 'نمایش رمز ورود'
showPassword: 'نمایش رمز ورود',
signUpTerms: 'با ثبت نام، با شرایط خدمات و سیاست حفظ حریم خصوصی ما موافقت می کنید.'
};
4 changes: 2 additions & 2 deletions src/i18n/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export default {
signUpTitle: 'Rekisteröidy',
signUpLabel: 'Rekisteröidy',
signUpSubmitLabel: 'Rekisteröidy',
signUpTerms: '',
signUpWithLabel: 'Rekisteröidy %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -127,5 +126,6 @@ export default {
mfaLoginInstructions: 'Ole hyvä ja anna mobiilisovelluksesi luoma tarkistuskoodi.',
mfaSubmitLabel: 'Kirjaudu',
mfaCodeErrorHint: 'Käytä %d numeroa',
showPassword: 'Näytä salasana'
showPassword: 'Näytä salasana',
signUpTerms: 'Ilmoittautumalla hyväksyt käyttöehdot ja tietosuojakäytännöt.'
};
5 changes: 3 additions & 2 deletions src/i18n/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export default {
sentLabel: 'Envoyé !',
signUpLabel: 'Inscription',
signUpSubmitLabel: 'Inscription',
signUpTerms: '',
signUpWithLabel: 'S’inscrire avec %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -136,5 +135,7 @@ export default {
'Veuillez entrer le code de vérification généré par votre application mobile.',
mfaSubmitLabel: "S'identifier",
mfaCodeErrorHint: 'Utilisez des numéros %d',
showPassword: 'Montrer le mot de passe'
showPassword: 'Montrer le mot de passe',
signUpTerms:
"En vous inscrivant, vous acceptez nos conditions d'utilisation et notre politique de confidentialité."
};
4 changes: 2 additions & 2 deletions src/i18n/hr.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export default {
signUpTitle: 'Registracija',
signUpLabel: 'Registracija',
signUpSubmitLabel: 'Registracija',
signUpTerms: '',
signUpWithLabel: 'Registracija s %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -132,5 +131,6 @@ export default {
mfaLoginInstructions:
'Upišite kôd za provjeru autentičnosti koji je stvorila vaša mobilna aplikacija.',
mfaSubmitLabel: 'Prijava',
mfaCodeErrorHint: 'Upotrijebi %d brojeve'
mfaCodeErrorHint: 'Upotrijebi %d brojeve',
signUpTerms: 'Prijavljivanjem prihvaćate naše uvjete pružanja usluge i pravila o privatnosti.'
};
5 changes: 3 additions & 2 deletions src/i18n/hu.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export default {
sentLabel: 'Elküldve!',
signUpLabel: 'Feliratkozás',
signUpSubmitLabel: 'Feliratkozás',
signUpTerms: '',
signUpWithLabel: 'Feliratkozás %s-val',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -127,5 +126,7 @@ export default {
mfaLoginInstructions: 'Kérjük adja meg az ellenőrző kódot generált a mobil alkalmazás.',
mfaSubmitLabel: 'Belépek',
mfaCodeErrorHint: 'Használja %d számok',
showPassword: 'Mutasd a jelszót'
showPassword: 'Mutasd a jelszót',
signUpTerms:
'Feliratkozással elfogadja a szolgáltatási feltételeinket és az adatvédelmi irányelveinket.'
};
4 changes: 2 additions & 2 deletions src/i18n/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default {
sentLabel: 'Inviato!',
signUpLabel: 'Registrati',
signUpSubmitLabel: 'Registrati',
signUpTerms: '',
signUpWithLabel: 'Registrati con %s',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -125,5 +124,6 @@ export default {
'Si prega di inserire il codice di verifica generato dalla tua applicazione mobile.',
mfaSubmitLabel: 'Accedere',
mfaCodeErrorHint: 'Usare %d numeri',
showPassword: 'Mostra password'
showPassword: 'Mostra password',
signUpTerms: "Iscrivendoti, accetti i nostri termini di servizio e l'informativa sulla privacy."
};
4 changes: 2 additions & 2 deletions src/i18n/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export default {
signUpTitle: 'ユーザー登録',
signUpLabel: 'ユーザー登録',
signUpSubmitLabel: 'ユーザー登録',
signUpTerms: '',
signUpWithLabel: '%sでユーザー登録',
socialLoginInstructions: '',
socialSignUpInstructions: '',
Expand All @@ -114,5 +113,6 @@ export default {
mfaLoginTitle: '二段階認証',
mfaLoginInstructions: 'スマートフォンアプリケーションで生成された確認コードを入力してください。',
mfaSubmitLabel: 'ログイン',
mfaCodeErrorHint: '%d個の数字を使用してください'
mfaCodeErrorHint: '%d個の数字を使用してください',
signUpTerms: 'サインアップすることで、利用規約とプライバシーポリシーに同意したことになります。'
};
Loading

0 comments on commit 41b922a

Please sign in to comment.