diff --git a/scripts/langindex.json b/scripts/langindex.json index a10ce8493..8ab3ebefc 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1326,6 +1326,8 @@ "core.login.createuserandpass": "moodle", "core.login.credentialsdescription": "local_moodlemobileapp", "core.login.emailconfirmsent": "moodle", + "core.login.emailconfirmsentnoemail": "local_moodlemobileapp", + "core.login.emailconfirmsentsuccess": "moodle", "core.login.emailnotmatch": "local_moodlemobileapp", "core.login.enterthewordsabove": "auth", "core.login.erroraccesscontrolalloworigin": "local_moodlemobileapp", @@ -1358,6 +1360,7 @@ "core.login.missingfirstname": "moodle", "core.login.missinglastname": "moodle", "core.login.mobileservicesnotenabled": "local_moodlemobileapp", + "core.login.mustconfirm": "moodle", "core.login.newaccount": "moodle", "core.login.newsitedescription": "local_moodlemobileapp", "core.login.notloggedin": "local_moodlemobileapp", @@ -1379,6 +1382,7 @@ "core.login.reconnect": "local_moodlemobileapp", "core.login.reconnectdescription": "local_moodlemobileapp", "core.login.reconnectssodescription": "local_moodlemobileapp", + "core.login.resendemail": "moodle", "core.login.searchby": "local_moodlemobileapp", "core.login.security_question": "auth", "core.login.selectacountry": "moodle", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 23e3c6a45..168c94738 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1325,6 +1325,8 @@ "core.login.createuserandpass": "Choose your username and password", "core.login.credentialsdescription": "Please provide your username and password to log in.", "core.login.emailconfirmsent": "
An email should have been sent to your address at {{$a}}
\nIt contains easy instructions to complete your registration.
\nIf you continue to have difficulty, contact the site administrator.
", + "core.login.emailconfirmsentnoemail": "An email should have been sent to your address.
It contains easy instructions to complete your registration.
If you continue to have difficulty, contact the site administrator.
", + "core.login.emailconfirmsentsuccess": "Confirmation email sent successfully", "core.login.emailnotmatch": "Emails do not match", "core.login.enterthewordsabove": "Enter the words above", "core.login.erroraccesscontrolalloworigin": "The cross-origin call you're trying to perform has been rejected. Please check https://docs.moodle.org/dev/Moodle_Mobile_development_using_Chrome_or_Chromium", @@ -1358,6 +1360,7 @@ "core.login.missingfirstname": "Missing given name", "core.login.missinglastname": "Missing surname", "core.login.mobileservicesnotenabled": "Mobile access is not enabled on your site. Please contact your site administrator if you think it should be enabled.", + "core.login.mustconfirm": "You need to confirm your account", "core.login.newaccount": "New account", "core.login.newsitedescription": "Please enter the URL of your Moodle site. Note that it might not be configured to work with this app.", "core.login.notloggedin": "You need to be logged in.", @@ -1379,6 +1382,7 @@ "core.login.reconnect": "Reconnect", "core.login.reconnectdescription": "Your authentication token is invalid or has expired. You have to reconnect to the site.", "core.login.reconnectssodescription": "Your authentication token is invalid or has expired. You have to reconnect to the site. You need to log in to the site in a browser window.", + "core.login.resendemail": "Resend email", "core.login.searchby": "Search by:", "core.login.security_question": "Security question", "core.login.selectacountry": "Select a country", diff --git a/src/core/login/lang/en.json b/src/core/login/lang/en.json index 561b7d81e..624ccd9f2 100644 --- a/src/core/login/lang/en.json +++ b/src/core/login/lang/en.json @@ -12,6 +12,8 @@ "createuserandpass": "Choose your username and password", "credentialsdescription": "Please provide your username and password to log in.", "emailconfirmsent": "An email should have been sent to your address at {{$a}}
\nIt contains easy instructions to complete your registration.
\nIf you continue to have difficulty, contact the site administrator.
", + "emailconfirmsentnoemail": "An email should have been sent to your address.
It contains easy instructions to complete your registration.
If you continue to have difficulty, contact the site administrator.
", + "emailconfirmsentsuccess": "Confirmation email sent successfully", "emailnotmatch": "Emails do not match", "enterthewordsabove": "Enter the words above", "erroraccesscontrolalloworigin": "The cross-origin call you're trying to perform has been rejected. Please check https://docs.moodle.org/dev/Moodle_Mobile_development_using_Chrome_or_Chromium", @@ -45,6 +47,7 @@ "missingfirstname": "Missing given name", "missinglastname": "Missing surname", "mobileservicesnotenabled": "Mobile access is not enabled on your site. Please contact your site administrator if you think it should be enabled.", + "mustconfirm": "You need to confirm your account", "newaccount": "New account", "newsitedescription": "Please enter the URL of your Moodle site. Note that it might not be configured to work with this app.", "notloggedin": "You need to be logged in.", @@ -66,6 +69,7 @@ "reconnect": "Reconnect", "reconnectdescription": "Your authentication token is invalid or has expired. You have to reconnect to the site.", "reconnectssodescription": "Your authentication token is invalid or has expired. You have to reconnect to the site. You need to log in to the site in a browser window.", + "resendemail": "Resend email", "searchby": "Search by:", "security_question": "Security question", "selectacountry": "Select a country", diff --git a/src/core/login/pages/credentials/credentials.ts b/src/core/login/pages/credentials/credentials.ts index 11c32714a..a286a4b0c 100644 --- a/src/core/login/pages/credentials/credentials.ts +++ b/src/core/login/pages/credentials/credentials.ts @@ -228,7 +228,7 @@ export class CoreLoginCredentialsPage { } }); }).catch((error) => { - this.loginHelper.treatUserTokenError(siteUrl, error); + this.loginHelper.treatUserTokenError(siteUrl, error, username, password); }).finally(() => { modal.dismiss(); }); diff --git a/src/core/login/pages/reconnect/reconnect.ts b/src/core/login/pages/reconnect/reconnect.ts index 27c853129..51f1cdaf7 100644 --- a/src/core/login/pages/reconnect/reconnect.ts +++ b/src/core/login/pages/reconnect/reconnect.ts @@ -154,7 +154,7 @@ export class CoreLoginReconnectPage { }); }); }).catch((error) => { - this.loginHelper.treatUserTokenError(siteUrl, error); + this.loginHelper.treatUserTokenError(siteUrl, error, username, password); }).finally(() => { modal.dismiss(); }); diff --git a/src/core/login/pages/site/site.ts b/src/core/login/pages/site/site.ts index 1bbdb8856..a7c630e6b 100644 --- a/src/core/login/pages/site/site.ts +++ b/src/core/login/pages/site/site.ts @@ -92,7 +92,7 @@ export class CoreLoginSitePage { this.domUtils.showErrorModal(error); }); }, (error) => { - this.loginHelper.treatUserTokenError(siteData.url, error); + this.loginHelper.treatUserTokenError(siteData.url, error, siteData.username, siteData.password); }).finally(() => { modal.dismiss(); }); diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index 079536ad1..9c51e160f 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -965,6 +965,66 @@ export class CoreLoginHelperProvider { }); } + /** + * Show a modal to inform the user that a confirmation email was sent, and a button to resend the email on 3.6+ sites. + * + * @param {string} siteUrl Site URL. + * @param {string} [email] Email of the user. If set displayed in the message. + * @param {string} [username] Username. If not set the button to resend email will not be shown. + * @param {string} [password] User password. If not set the button to resend email will not be shown. + */ + protected showNotConfirmedModal(siteUrl: string, email?: string, username?: string, password?: string): void { + const title = this.translate.instant('core.login.mustconfirm'); + let message; + if (email) { + message = this.translate.instant('core.login.emailconfirmsent', { $a: email }); + } else { + message = this.translate.instant('core.login.emailconfirmsentnoemail'); + } + + // Check whether we need to display the resend button or not. + let promise; + if (username && password) { + const modal = this.domUtils.showModalLoading(); + // We don't have site info before login, the only way to check if the WS is available is by calling it. + const preSets = { siteUrl }; + promise = this.wsProvider.callAjax('core_auth_resend_confirmation_email', {}, preSets).catch((error) => { + // If the WS responds with an invalid parameter error it means the WS is avaiable. + return Promise.resolve(error && error.errorcode === 'invalidparameter'); + }).finally(() => { + modal.dismiss(); + }); + } else { + promise = Promise.resolve(false); + } + + promise.then((canResend) => { + if (canResend) { + const okText = this.translate.instant('core.login.resendemail'); + const cancelText = this.translate.instant('core.close'); + + this.domUtils.showConfirm(message, title, okText, cancelText).then(() => { + // Call the WS to resend the confirmation email. + const modal = this.domUtils.showModalLoading('core.sending', true); + const data = { username, password }; + const preSets = { siteUrl }; + this.wsProvider.callAjax('core_auth_resend_confirmation_email', data, preSets).then((response) => { + const message = this.translate.instant('core.login.emailconfirmsentsuccess'); + this.domUtils.showAlert(this.translate.instant('core.success'), message); + }).catch((error) => { + this.domUtils.showErrorModal(error); + }).finally(() => { + modal.dismiss(); + }); + }).catch(() => { + // Dialog dismissed. + }); + } else { + this.domUtils.showAlert(title, message); + } + }); + } + /** * Function called when site policy is not agreed. Reserved for core use. * @@ -998,10 +1058,14 @@ export class CoreLoginHelperProvider { * * @param {string} siteUrl Site URL to construct change password URL. * @param {any} error Error object containing errorcode and error message. + * @param {string} [username] Username. + * @param {string} [password] User password. */ - treatUserTokenError(siteUrl: string, error: any): void { + treatUserTokenError(siteUrl: string, error: any, username?: string, password?: string): void { if (error.errorcode == 'forcepasswordchangenotice') { this.openChangePassword(siteUrl, this.textUtils.getErrorMessageFromError(error)); + } else if (error.errorcode == 'usernotconfirmed') { + this.showNotConfirmedModal(siteUrl, undefined, username, password); } else if (error.errorcode == 'legacymoodleversion') { this.showLegacyNoticeModal(this.textUtils.getErrorMessageFromError(error)); } else {