Merge pull request #1598 from albertgasset/MOBILE-2599

MOBILE-2599 login: Add button to resend confirmation email
main
Juan Leyva 2018-11-12 16:29:18 +01:00 committed by GitHub
commit 16dd286fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 4 deletions

View File

@ -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",

View File

@ -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": "<p>An email should have been sent to your address at <b>{{$a}}</b></p>\n <p>It contains easy instructions to complete your registration.</p>\n <p>If you continue to have difficulty, contact the site administrator.</p>",
"core.login.emailconfirmsentnoemail": "<p>An email should have been sent to your address.</p><p>It contains easy instructions to complete your registration.</p><p>If you continue to have difficulty, contact the site administrator.</p>",
"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",

View File

@ -12,6 +12,8 @@
"createuserandpass": "Choose your username and password",
"credentialsdescription": "Please provide your username and password to log in.",
"emailconfirmsent": "<p>An email should have been sent to your address at <b>{{$a}}</b></p>\n <p>It contains easy instructions to complete your registration.</p>\n <p>If you continue to have difficulty, contact the site administrator.</p>",
"emailconfirmsentnoemail": "<p>An email should have been sent to your address.</p><p>It contains easy instructions to complete your registration.</p><p>If you continue to have difficulty, contact the site administrator.</p>",
"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",

View File

@ -228,7 +228,7 @@ export class CoreLoginCredentialsPage {
}
});
}).catch((error) => {
this.loginHelper.treatUserTokenError(siteUrl, error);
this.loginHelper.treatUserTokenError(siteUrl, error, username, password);
}).finally(() => {
modal.dismiss();
});

View File

@ -154,7 +154,7 @@ export class CoreLoginReconnectPage {
});
});
}).catch((error) => {
this.loginHelper.treatUserTokenError(siteUrl, error);
this.loginHelper.treatUserTokenError(siteUrl, error, username, password);
}).finally(() => {
modal.dismiss();
});

View File

@ -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();
});

View File

@ -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 {