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.selectacountry": "moodle",
|
||||||
"core.login.selectsite": "local_moodlemobileapp",
|
"core.login.selectsite": "local_moodlemobileapp",
|
||||||
"core.login.signupplugindisabled": "local_moodlemobileapp",
|
"core.login.signupplugindisabled": "local_moodlemobileapp",
|
||||||
|
"core.login.signuprequiredfieldnotsupported": "local_moodlemobileapp",
|
||||||
"core.login.siteaddress": "local_moodlemobileapp",
|
"core.login.siteaddress": "local_moodlemobileapp",
|
||||||
"core.login.sitehasredirect": "local_moodlemobileapp",
|
"core.login.sitehasredirect": "local_moodlemobileapp",
|
||||||
"core.login.siteinmaintenance": "local_moodlemobileapp",
|
"core.login.siteinmaintenance": "local_moodlemobileapp",
|
||||||
|
|
|
@ -1828,6 +1828,7 @@
|
||||||
"core.login.selectacountry": "Select a country",
|
"core.login.selectacountry": "Select a country",
|
||||||
"core.login.selectsite": "Please select your site:",
|
"core.login.selectsite": "Please select your site:",
|
||||||
"core.login.signupplugindisabled": "{{$a}} is not enabled.",
|
"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.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.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",
|
"core.login.siteinmaintenance": "Your site is in maintenance mode",
|
||||||
|
|
|
@ -102,6 +102,7 @@
|
||||||
"selectacountry": "Select a country",
|
"selectacountry": "Select a country",
|
||||||
"selectsite": "Please select your site:",
|
"selectsite": "Please select your site:",
|
||||||
"signupplugindisabled": "{{$a}} is not enabled.",
|
"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",
|
"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.",
|
"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",
|
"siteinmaintenance": "Your site is in maintenance mode",
|
||||||
|
|
|
@ -16,8 +16,20 @@
|
||||||
|
|
||||||
<core-loading [hideUntil]="settingsLoaded" *ngIf="!isMinor">
|
<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. -->
|
<!-- 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>
|
<ion-item-divider text-wrap>
|
||||||
<p class="item-heading">{{ 'core.agelocationverification' | translate }}</p>
|
<p class="item-heading">{{ 'core.agelocationverification' | translate }}</p>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
|
@ -47,7 +59,7 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- Signup 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>
|
<ion-item text-wrap text-center>
|
||||||
<!-- If no sitename show big siteurl. -->
|
<!-- If no sitename show big siteurl. -->
|
||||||
<p *ngIf="!siteName" padding class="item-heading">{{siteUrl}}</p>
|
<p *ngIf="!siteName" padding class="item-heading">{{siteUrl}}</p>
|
||||||
|
@ -143,7 +155,7 @@
|
||||||
</form>
|
</form>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
|
|
||||||
<ion-list *ngIf="isMinor">
|
<ion-list *ngIf="allRequiredSupported && isMinor">
|
||||||
<ion-item-divider text-wrap>
|
<ion-item-divider text-wrap>
|
||||||
<p *ngIf="siteName" class="item-heading padding"><core-format-text [text]="siteName" [filter]="false"></core-format-text></p>
|
<p *ngIf="siteName" class="item-heading padding"><core-format-text [text]="siteName" [filter]="false"></core-format-text></p>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
|
|
|
@ -48,6 +48,8 @@ export class CoreLoginEmailSignupPage {
|
||||||
countries: any;
|
countries: any;
|
||||||
categories: any[];
|
categories: any[];
|
||||||
settingsLoaded = false;
|
settingsLoaded = false;
|
||||||
|
allRequiredSupported = true;
|
||||||
|
signupUrl: string;
|
||||||
captcha = {
|
captcha = {
|
||||||
recaptcharesponse: ''
|
recaptcharesponse: ''
|
||||||
};
|
};
|
||||||
|
@ -136,41 +138,51 @@ 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> {
|
protected async fetchData(): Promise<void> {
|
||||||
|
try {
|
||||||
// Get site config.
|
// Get site config.
|
||||||
return this.sitesProvider.getSitePublicConfig(this.siteUrl).then((config) => {
|
this.siteConfig = await this.sitesProvider.getSitePublicConfig(this.siteUrl);
|
||||||
this.siteConfig = config;
|
this.signupUrl = this.textUtils.concatenatePaths(this.siteConfig.httpswwwroot, 'login/signup.php');
|
||||||
|
|
||||||
if (this.treatSiteConfig(config)) {
|
if (this.treatSiteConfig(this.siteConfig)) {
|
||||||
// Check content verification.
|
// Check content verification.
|
||||||
if (typeof this.ageDigitalConsentVerification == 'undefined') {
|
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;
|
const result = await this.utils.ignoreErrors(this.wsProvider.callAjax(
|
||||||
}).catch((e) => {
|
'core_auth_is_age_digital_consent_verification_enabled', {}, {siteUrl: this.siteUrl }));
|
||||||
// Capture exceptions, fail silently.
|
|
||||||
}).then(() => {
|
this.ageDigitalConsentVerification = result && result.status;
|
||||||
return this.getSignupSettings();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return this.getSignupSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.getSignupSettings();
|
||||||
}
|
}
|
||||||
}).then(() => {
|
|
||||||
this.completeFormGroup();
|
this.completeFormGroup();
|
||||||
}).catch((err) => {
|
} catch (error) {
|
||||||
this.domUtils.showErrorModal(err);
|
if (this.allRequiredSupported) {
|
||||||
});
|
this.domUtils.showErrorModal(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get signup settings from server.
|
* Get signup settings from server.
|
||||||
|
*
|
||||||
|
* @return Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected getSignupSettings(): Promise<any> {
|
protected async getSignupSettings(): Promise<void> {
|
||||||
return this.wsProvider.callAjax('auth_email_get_signup_settings', {}, { siteUrl: this.siteUrl }).then((settings) => {
|
const settings = await this.wsProvider.callAjax('auth_email_get_signup_settings', {}, { siteUrl: this.siteUrl });
|
||||||
|
|
||||||
|
if (this.userProfileFieldDelegate.hasRequiredUnsupportedField(settings.profilefields)) {
|
||||||
|
this.allRequiredSupported = false;
|
||||||
|
|
||||||
|
throw new Error(this.translate.instant('core.login.signuprequiredfieldnotsupported'));
|
||||||
|
}
|
||||||
|
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.categories = this.loginHelper.formatProfileFieldsForSignup(settings.profilefields);
|
this.categories = this.loginHelper.formatProfileFieldsForSignup(settings.profilefields);
|
||||||
|
|
||||||
|
@ -189,10 +201,7 @@ export class CoreLoginEmailSignupPage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.utils.getCountryListSorted().then((countries) => {
|
this.countries = await this.utils.getCountryListSorted();
|
||||||
this.countries = countries;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -157,4 +157,20 @@ export class CoreUserProfileFieldDelegate extends CoreDelegate {
|
||||||
return result;
|
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;
|
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) {}
|
export class CoreUtils extends makeSingleton(CoreUtilsProvider) {}
|
||||||
|
|
Loading…
Reference in New Issue