diff --git a/scripts/langindex.json b/scripts/langindex.json index 2c1ca2a62..8bd92d9cc 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1828,6 +1828,7 @@ "core.login.selectacountry": "moodle", "core.login.selectsite": "local_moodlemobileapp", "core.login.signupplugindisabled": "local_moodlemobileapp", + "core.login.signuprequiredfieldnotsupported": "local_moodlemobileapp", "core.login.siteaddress": "local_moodlemobileapp", "core.login.sitehasredirect": "local_moodlemobileapp", "core.login.siteinmaintenance": "local_moodlemobileapp", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index f3f916c98..dfc6fd17d 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1828,6 +1828,7 @@ "core.login.selectacountry": "Select a country", "core.login.selectsite": "Please select your site:", "core.login.signupplugindisabled": "{{$a}} is not enabled.", + "core.login.signuprequiredfieldnotsupported": "The signup form contains a required custom field that isn't supported in the app. Please create your account using a web browser.", "core.login.siteaddress": "Your site", "core.login.sitehasredirect": "Your site contains at least one HTTP redirect. The app cannot follow redirects, this could be the issue that's preventing the app from connecting to your site.", "core.login.siteinmaintenance": "Your site is in maintenance mode", diff --git a/src/core/login/lang/en.json b/src/core/login/lang/en.json index c0003e51b..fb28b87c2 100644 --- a/src/core/login/lang/en.json +++ b/src/core/login/lang/en.json @@ -102,6 +102,7 @@ "selectacountry": "Select a country", "selectsite": "Please select your site:", "signupplugindisabled": "{{$a}} is not enabled.", + "signuprequiredfieldnotsupported": "The signup form contains a required custom field that isn't supported in the app. Please create your account using a web browser.", "siteaddress": "Your site", "sitehasredirect": "Your site contains at least one HTTP redirect. The app cannot follow redirects, this could be the issue that's preventing the app from connecting to your site.", "siteinmaintenance": "Your site is in maintenance mode", diff --git a/src/core/login/pages/email-signup/email-signup.html b/src/core/login/pages/email-signup/email-signup.html index 3e52b4b6c..fd8a226e4 100644 --- a/src/core/login/pages/email-signup/email-signup.html +++ b/src/core/login/pages/email-signup/email-signup.html @@ -16,8 +16,20 @@ + + + + {{ 'core.login.signuprequiredfieldnotsupported' | translate }} + + + + {{ 'core.openinbrowser' | translate }} + + + + -
+

{{ 'core.agelocationverification' | translate }}

@@ -47,7 +59,7 @@
-
+

{{siteUrl}}

@@ -143,7 +155,7 @@
- +

diff --git a/src/core/login/pages/email-signup/email-signup.ts b/src/core/login/pages/email-signup/email-signup.ts index fc0eb808d..496ddc269 100644 --- a/src/core/login/pages/email-signup/email-signup.ts +++ b/src/core/login/pages/email-signup/email-signup.ts @@ -48,6 +48,8 @@ export class CoreLoginEmailSignupPage { countries: any; categories: any[]; settingsLoaded = false; + allRequiredSupported = true; + signupUrl: string; captcha = { recaptcharesponse: '' }; @@ -136,63 +138,70 @@ export class CoreLoginEmailSignupPage { } /** - * Fetch the required data from the server- + * Fetch the required data from the server. + * + * @return Promise resolved when done. */ - protected fetchData(): Promise { - // Get site config. - return this.sitesProvider.getSitePublicConfig(this.siteUrl).then((config) => { - this.siteConfig = config; + protected async fetchData(): Promise { + try { + // Get site config. + this.siteConfig = await this.sitesProvider.getSitePublicConfig(this.siteUrl); + this.signupUrl = this.textUtils.concatenatePaths(this.siteConfig.httpswwwroot, 'login/signup.php'); - if (this.treatSiteConfig(config)) { + if (this.treatSiteConfig(this.siteConfig)) { // 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(); + const result = await this.utils.ignoreErrors(this.wsProvider.callAjax( + 'core_auth_is_age_digital_consent_verification_enabled', {}, {siteUrl: this.siteUrl })); + + this.ageDigitalConsentVerification = result && result.status; } + + await this.getSignupSettings(); } - }).then(() => { + this.completeFormGroup(); - }).catch((err) => { - this.domUtils.showErrorModal(err); - }); + } catch (error) { + if (this.allRequiredSupported) { + this.domUtils.showErrorModal(error); + } + } } /** * Get signup settings from server. + * + * @return Promise resolved when done. */ - protected getSignupSettings(): Promise { - return this.wsProvider.callAjax('auth_email_get_signup_settings', {}, { siteUrl: this.siteUrl }).then((settings) => { - this.settings = settings; - this.categories = this.loginHelper.formatProfileFieldsForSignup(settings.profilefields); + protected async getSignupSettings(): Promise { + const settings = await this.wsProvider.callAjax('auth_email_get_signup_settings', {}, { siteUrl: this.siteUrl }); - if (this.settings.recaptchapublickey) { - this.captcha.recaptcharesponse = ''; // Reset captcha. - } + if (this.userProfileFieldDelegate.hasRequiredUnsupportedField(settings.profilefields)) { + this.allRequiredSupported = false; - if (!this.countryControl.value) { - this.countryControl.setValue(settings.country || ''); - } + throw new Error(this.translate.instant('core.login.signuprequiredfieldnotsupported')); + } - this.namefieldsErrors = {}; - if (settings.namefields) { - settings.namefields.forEach((field) => { - this.namefieldsErrors[field] = this.loginHelper.getErrorMessages('core.login.missing' + field); - }); - } + this.settings = settings; + this.categories = this.loginHelper.formatProfileFieldsForSignup(settings.profilefields); - return this.utils.getCountryListSorted().then((countries) => { - this.countries = countries; + if (this.settings.recaptchapublickey) { + this.captcha.recaptcharesponse = ''; // Reset captcha. + } + + if (!this.countryControl.value) { + this.countryControl.setValue(settings.country || ''); + } + + this.namefieldsErrors = {}; + if (settings.namefields) { + settings.namefields.forEach((field) => { + this.namefieldsErrors[field] = this.loginHelper.getErrorMessages('core.login.missing' + field); }); - }); + } + + this.countries = await this.utils.getCountryListSorted(); } /** diff --git a/src/core/user/providers/user-profile-field-delegate.ts b/src/core/user/providers/user-profile-field-delegate.ts index 4acef8d5e..e48879eb1 100644 --- a/src/core/user/providers/user-profile-field-delegate.ts +++ b/src/core/user/providers/user-profile-field-delegate.ts @@ -157,4 +157,20 @@ export class CoreUserProfileFieldDelegate extends CoreDelegate { return result; }); } + + /** + * Check if any of the profile fields is not supported in the app. + * + * @param fields List of fields. + * @return Whether any of the profile fields is not supported in the app. + */ + hasRequiredUnsupportedField(fields: any[]): boolean { + if (!fields || !fields.length) { + return false; + } + + return fields.some((field) => { + return field.required && !this.hasHandler(field.type || field.datatype); + }); + } } diff --git a/src/providers/utils/utils.ts b/src/providers/utils/utils.ts index 8ee4a2798..92baac78d 100644 --- a/src/providers/utils/utils.ts +++ b/src/providers/utils/utils.ts @@ -1576,6 +1576,22 @@ export class CoreUtilsProvider { delete this.qrScanData; } + + /** + * Ignore errors from a promise. + * + * @param promise Promise to ignore errors. + * @return Promise with ignored errors. + */ + async ignoreErrors(promise: Promise): Promise { + try { + const result = await promise; + + return result; + } catch (error) { + // Ignore errors. + } + } } export class CoreUtils extends makeSingleton(CoreUtilsProvider) {}