From 98049ab8abbbfff5c5ed278001bebc527ccf443e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 16 May 2018 14:43:25 +0200 Subject: [PATCH] MOBILE-2415 signup: Support age verification form --- .../login/pages/credentials/credentials.html | 2 +- .../pages/email-signup/email-signup.html | 57 ++++++++++++- .../login/pages/email-signup/email-signup.ts | 81 ++++++++++++++++++- src/core/login/pages/reconnect/reconnect.html | 2 +- src/lang/en.json | 9 +++ 5 files changed, 142 insertions(+), 9 deletions(-) diff --git a/src/core/login/pages/credentials/credentials.html b/src/core/login/pages/credentials/credentials.html index 6aee0c300..98e9582ac 100644 --- a/src/core/login/pages/credentials/credentials.html +++ b/src/core/login/pages/credentials/credentials.html @@ -14,7 +14,7 @@

{{siteUrl}}

-

{{siteName}}

+

{{siteUrl}}

diff --git a/src/core/login/pages/email-signup/email-signup.html b/src/core/login/pages/email-signup/email-signup.html index afef81dc1..51e0ec216 100644 --- a/src/core/login/pages/email-signup/email-signup.html +++ b/src/core/login/pages/email-signup/email-signup.html @@ -10,17 +10,49 @@ - + - - + + + + + +

{{ 'core.agelocationverification' | translate }}

+
+ + + {{ 'core.whatisyourage' | translate }} + + + + + {{ 'core.wheredoyoulive' | translate }} + + {{ 'core.login.selectacountry' | translate }} + {{countries[key]}} + + + + + + + + + +

{{ 'core.whyisthisrequired' | translate }}

+

{{ 'core.explanationdigitalminor' | translate }}

+
+ + + +

{{siteUrl}}

-

{{siteName}}

+

{{siteUrl}}

@@ -108,4 +140,21 @@
+ + + +

+
+ +

{{ 'core.considereddigitalminor' | translate }}

+

{{ 'core.digitalminor_desc' | translate }}

+

{{ supportName }}

+

{{ supportEmail }}

+
+ +
+
+
diff --git a/src/core/login/pages/email-signup/email-signup.ts b/src/core/login/pages/email-signup/email-signup.ts index 4bc221699..4f14c5407 100644 --- a/src/core/login/pages/email-signup/email-signup.ts +++ b/src/core/login/pages/email-signup/email-signup.ts @@ -21,7 +21,7 @@ import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreWSProvider } from '@providers/ws'; import { CoreLoginHelperProvider } from '../../providers/helper'; -import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { CoreUserProfileFieldDelegate } from '@core/user/providers/user-profile-field-delegate'; /** @@ -34,6 +34,7 @@ import { CoreUserProfileFieldDelegate } from '@core/user/providers/user-profile- }) export class CoreLoginEmailSignupPage { @ViewChild(Content) content: Content; + signupForm: FormGroup; siteUrl: string; siteConfig: any; @@ -48,6 +49,14 @@ export class CoreLoginEmailSignupPage { recaptcharesponse: '' }; + // Data for age verification. + ageVerificationForm: FormGroup; + countryControl: FormControl; + isMinor = false; // Whether the user is minor age. + ageDigitalConsentVerification: boolean; // Whether the age verification is enabled. + supportName: string; + supportEmail: string; + // Validation errors. usernameErrors: any; passwordErrors: any; @@ -63,6 +72,13 @@ export class CoreLoginEmailSignupPage { this.siteUrl = navParams.get('siteUrl'); + // Create the ageVerificationForm. + this.ageVerificationForm = this.fb.group({ + age: ['', Validators.required] + }); + this.countryControl = this.fb.control('', Validators.required); + this.ageVerificationForm.addControl('country', this.countryControl); + // Create the signupForm with the basic controls. More controls will be added later. this.signupForm = this.fb.group({ username: ['', Validators.required], @@ -115,7 +131,20 @@ export class CoreLoginEmailSignupPage { this.siteConfig = config; if (this.treatSiteConfig(config)) { - return this.getSignupSettings(); + // Check content verification. + if (typeof this.ageDigitalConsentVerification == 'undefined') { + return this.wsProvider.callAjax('core_auth_is_age_digital_consent_verification_enabled', {}, + {siteUrl: this.siteUrl }).then((result) => { + + this.ageDigitalConsentVerification = result.status; + }).catch((e) => { + // Capture exceptions, fail silently. + }).then(() => { + return this.getSignupSettings(); + }); + } else { + return this.getSignupSettings(); + } } }).then(() => { this.completeFormGroup(); @@ -136,6 +165,10 @@ export class CoreLoginEmailSignupPage { this.captcha.recaptcharesponse = ''; // Reset captcha. } + if (!this.countryControl.value) { + this.countryControl.setValue(settings.country || ''); + } + this.namefieldsErrors = {}; if (settings.namefields) { settings.namefields.forEach((field) => { @@ -160,6 +193,10 @@ export class CoreLoginEmailSignupPage { if (siteConfig && siteConfig.registerauth == 'email' && !this.loginHelper.isEmailSignupDisabled(siteConfig)) { this.siteName = siteConfig.sitename; this.authInstructions = siteConfig.authinstructions; + this.ageDigitalConsentVerification = siteConfig.agedigitalconsentverification; + this.supportName = siteConfig.supportname; + this.supportEmail = siteConfig.supportemail; + this.countryControl.setValue(siteConfig.country || ''); return true; } else { @@ -229,7 +266,7 @@ export class CoreLoginEmailSignupPage { if (result.warnings && result.warnings.length) { let error = result.warnings[0].message; if (error == 'incorrect-captcha-sol') { - error = this.translate.instant('mm.login.recaptchaincorrect'); + error = this.translate.instant('core.login.recaptchaincorrect'); } this.domUtils.showErrorModal(error); @@ -252,4 +289,42 @@ export class CoreLoginEmailSignupPage { protected showAuthInstructions(): void { this.textUtils.expandText(this.translate.instant('core.login.instructions'), this.authInstructions); } + + /** + * Show contact information on site (we have to display again the age verification form). + */ + showContactOnSite(): void { + this.utils.openInBrowser(this.siteUrl + '/login/verify_age_location.php'); + } + + /** + * Verify Age. + */ + verifyAge(): void { + if (!this.ageVerificationForm.valid) { + this.domUtils.showErrorModal('core.errorinvalidform', true); + + return; + } + + const modal = this.domUtils.showModalLoading('core.sending', true), + params = this.ageVerificationForm.value; + + params.age = parseInt(params.age, 10); // Use just the integer part. + + this.wsProvider.callAjax('core_auth_is_minor', params, {siteUrl: this.siteUrl}).then((result) => { + if (!result.status) { + // Not a minor, go ahead! + this.ageDigitalConsentVerification = false; + } else { + // Is a minor!! + this.isMinor = true; + } + }).catch(() => { + // Something wrong, redirect to the site. + this.domUtils.showErrorModal('There was an error verifying your age, please try again using the browser.'); + }).finally(() => { + modal.dismiss(); + }); + } } diff --git a/src/core/login/pages/reconnect/reconnect.html b/src/core/login/pages/reconnect/reconnect.html index ee94ea5e6..74350213e 100644 --- a/src/core/login/pages/reconnect/reconnect.html +++ b/src/core/login/pages/reconnect/reconnect.html @@ -18,7 +18,7 @@

{{siteUrl}}

-

{{siteName}}

+

{{siteUrl}}

diff --git a/src/lang/en.json b/src/lang/en.json index 2a0e60e40..0a5d19c35 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -1,6 +1,7 @@ { "accounts": "Accounts", "add": "Add", + "agelocationverification": "Age and location verification", "allparticipants": "All participants", "android": "Android", "answer": "Answer", @@ -34,6 +35,7 @@ "confirmdeletefile": "Are you sure you want to delete this file?", "confirmloss": "Are you sure? All changes will be lost.", "confirmopeninbrowser": "Do you want to open it in browser?", + "considereddigitalminor": "You are considered to be a digital minor.", "content": "Content", "continue": "Continue", "contenteditingsynced": "The content you are editing has been synced.", @@ -57,6 +59,8 @@ "dflastweekdate": "ddd", "dfmediumdate": "LLL", "dftimedate": "h[:]mm A", + "digitalminor": "Digital minor", + "digitalminor_desc": "To create an account on this site please have your parent/guardian contact the following person.", "discard": "Discard", "dismiss": "Dismiss", "done": "Done", @@ -79,6 +83,7 @@ "errorrenamefile": "Error renaming the file. Please try again.", "errorsync": "An error occurred while synchronizing. Please try again.", "errorsyncblocked": "This {{$a}} cannot be synchronized right now because of an ongoing process. Please try again later. If the problem persists, try restarting the app.", + "explanationdigitalminor": "This information is required to determine if your age is over the digital age of consent. This is the age when an individual can consent to terms and conditions and their data being legally stored and processed.", "filename": "Filename", "filenameexist": "File name already exists: {{$a}}", "folder": "Folder", @@ -168,6 +173,7 @@ "phone": "Phone", "pictureof": "Picture of {{$a}}", "previous": "Previous", + "proceed": "Proceed", "pulltorefresh": "Pull to refresh", "quotausage": "You have currently used {{$a.used}} of your {{$a.total}} limit.", "redirectingtosite": "You will be redirected to site.", @@ -223,8 +229,11 @@ "view": "View", "viewprofile": "View profile", "warningofflinedatadeleted": "Offline data of {{component}} '{{name}}' has been deleted. {{error}}", + "whatisyourage": "What is your age?", + "wheredoyoulive": "In which country do you live?", "whoops": "Oops!", "whyisthishappening": "Why is this happening?", + "whyisthisrequired": "Why is this required?", "windowsphone": "Windows Phone", "wsfunctionnotavailable": "The webservice function is not available.", "year" : "year",