Merge pull request #2482 from dpalou/MOBILE-3435
MOBILE-3435 signup: Display error if it has required unsupported fieldmain
commit
25933d2429
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -16,8 +16,20 @@
|
|||
|
||||
<core-loading [hideUntil]="settingsLoaded" *ngIf="!isMinor">
|
||||
|
||||
<!-- Site has an unsupported required field. -->
|
||||
<ion-list *ngIf="!allRequiredSupported">
|
||||
<ion-item text-wrap>
|
||||
{{ 'core.login.signuprequiredfieldnotsupported' | translate }}
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<a ion-button block [href]="signupUrl" core-link [autoLogin]="no">
|
||||
{{ 'core.openinbrowser' | translate }}
|
||||
</a>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
|
||||
<!-- Age verification. -->
|
||||
<form ion-list *ngIf="settingsLoaded && settings && ageDigitalConsentVerification" [formGroup]="ageVerificationForm" (ngSubmit)="verifyAge($event)" #ageForm>
|
||||
<form ion-list *ngIf="allRequiredSupported && settingsLoaded && settings && ageDigitalConsentVerification" [formGroup]="ageVerificationForm" (ngSubmit)="verifyAge($event)" #ageForm>
|
||||
<ion-item-divider text-wrap>
|
||||
<p class="item-heading">{{ 'core.agelocationverification' | translate }}</p>
|
||||
</ion-item-divider>
|
||||
|
@ -47,7 +59,7 @@
|
|||
</form>
|
||||
|
||||
<!-- Signup form. -->
|
||||
<form ion-list *ngIf="settingsLoaded && settings && !ageDigitalConsentVerification" [formGroup]="signupForm" (ngSubmit)="create($event)" #signupFormEl>
|
||||
<form ion-list *ngIf="allRequiredSupported && settingsLoaded && settings && !ageDigitalConsentVerification" [formGroup]="signupForm" (ngSubmit)="create($event)" #signupFormEl>
|
||||
<ion-item text-wrap text-center>
|
||||
<!-- If no sitename show big siteurl. -->
|
||||
<p *ngIf="!siteName" padding class="item-heading">{{siteUrl}}</p>
|
||||
|
@ -143,7 +155,7 @@
|
|||
</form>
|
||||
</core-loading>
|
||||
|
||||
<ion-list *ngIf="isMinor">
|
||||
<ion-list *ngIf="allRequiredSupported && isMinor">
|
||||
<ion-item-divider text-wrap>
|
||||
<p *ngIf="siteName" class="item-heading padding"><core-format-text [text]="siteName" [filter]="false"></core-format-text></p>
|
||||
</ion-item-divider>
|
||||
|
|
|
@ -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<any> {
|
||||
// Get site config.
|
||||
return this.sitesProvider.getSitePublicConfig(this.siteUrl).then((config) => {
|
||||
this.siteConfig = config;
|
||||
protected async fetchData(): Promise<void> {
|
||||
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<any> {
|
||||
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<void> {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T>(promise: Promise<T>): Promise<T | undefined> {
|
||||
try {
|
||||
const result = await promise;
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
// Ignore errors.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class CoreUtils extends makeSingleton(CoreUtilsProvider) {}
|
||||
|
|
Loading…
Reference in New Issue