forked from EVOgeek/Vmeda.Online
		
	Merge pull request #1598 from albertgasset/MOBILE-2599
MOBILE-2599 login: Add button to resend confirmation email
This commit is contained in:
		
						commit
						16dd286fcf
					
				@ -1326,6 +1326,8 @@
 | 
				
			|||||||
  "core.login.createuserandpass": "moodle",
 | 
					  "core.login.createuserandpass": "moodle",
 | 
				
			||||||
  "core.login.credentialsdescription": "local_moodlemobileapp",
 | 
					  "core.login.credentialsdescription": "local_moodlemobileapp",
 | 
				
			||||||
  "core.login.emailconfirmsent": "moodle",
 | 
					  "core.login.emailconfirmsent": "moodle",
 | 
				
			||||||
 | 
					  "core.login.emailconfirmsentnoemail": "local_moodlemobileapp",
 | 
				
			||||||
 | 
					  "core.login.emailconfirmsentsuccess": "moodle",
 | 
				
			||||||
  "core.login.emailnotmatch": "local_moodlemobileapp",
 | 
					  "core.login.emailnotmatch": "local_moodlemobileapp",
 | 
				
			||||||
  "core.login.enterthewordsabove": "auth",
 | 
					  "core.login.enterthewordsabove": "auth",
 | 
				
			||||||
  "core.login.erroraccesscontrolalloworigin": "local_moodlemobileapp",
 | 
					  "core.login.erroraccesscontrolalloworigin": "local_moodlemobileapp",
 | 
				
			||||||
@ -1358,6 +1360,7 @@
 | 
				
			|||||||
  "core.login.missingfirstname": "moodle",
 | 
					  "core.login.missingfirstname": "moodle",
 | 
				
			||||||
  "core.login.missinglastname": "moodle",
 | 
					  "core.login.missinglastname": "moodle",
 | 
				
			||||||
  "core.login.mobileservicesnotenabled": "local_moodlemobileapp",
 | 
					  "core.login.mobileservicesnotenabled": "local_moodlemobileapp",
 | 
				
			||||||
 | 
					  "core.login.mustconfirm": "moodle",
 | 
				
			||||||
  "core.login.newaccount": "moodle",
 | 
					  "core.login.newaccount": "moodle",
 | 
				
			||||||
  "core.login.newsitedescription": "local_moodlemobileapp",
 | 
					  "core.login.newsitedescription": "local_moodlemobileapp",
 | 
				
			||||||
  "core.login.notloggedin": "local_moodlemobileapp",
 | 
					  "core.login.notloggedin": "local_moodlemobileapp",
 | 
				
			||||||
@ -1379,6 +1382,7 @@
 | 
				
			|||||||
  "core.login.reconnect": "local_moodlemobileapp",
 | 
					  "core.login.reconnect": "local_moodlemobileapp",
 | 
				
			||||||
  "core.login.reconnectdescription": "local_moodlemobileapp",
 | 
					  "core.login.reconnectdescription": "local_moodlemobileapp",
 | 
				
			||||||
  "core.login.reconnectssodescription": "local_moodlemobileapp",
 | 
					  "core.login.reconnectssodescription": "local_moodlemobileapp",
 | 
				
			||||||
 | 
					  "core.login.resendemail": "moodle",
 | 
				
			||||||
  "core.login.searchby": "local_moodlemobileapp",
 | 
					  "core.login.searchby": "local_moodlemobileapp",
 | 
				
			||||||
  "core.login.security_question": "auth",
 | 
					  "core.login.security_question": "auth",
 | 
				
			||||||
  "core.login.selectacountry": "moodle",
 | 
					  "core.login.selectacountry": "moodle",
 | 
				
			||||||
 | 
				
			|||||||
@ -1325,6 +1325,8 @@
 | 
				
			|||||||
    "core.login.createuserandpass": "Choose your username and password",
 | 
					    "core.login.createuserandpass": "Choose your username and password",
 | 
				
			||||||
    "core.login.credentialsdescription": "Please provide your username and password to log in.",
 | 
					    "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.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.emailnotmatch": "Emails do not match",
 | 
				
			||||||
    "core.login.enterthewordsabove": "Enter the words above",
 | 
					    "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",
 | 
					    "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.missingfirstname": "Missing given name",
 | 
				
			||||||
    "core.login.missinglastname": "Missing surname",
 | 
					    "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.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.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.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.",
 | 
					    "core.login.notloggedin": "You need to be logged in.",
 | 
				
			||||||
@ -1379,6 +1382,7 @@
 | 
				
			|||||||
    "core.login.reconnect": "Reconnect",
 | 
					    "core.login.reconnect": "Reconnect",
 | 
				
			||||||
    "core.login.reconnectdescription": "Your authentication token is invalid or has expired. You have to reconnect to the site.",
 | 
					    "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.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.searchby": "Search by:",
 | 
				
			||||||
    "core.login.security_question": "Security question",
 | 
					    "core.login.security_question": "Security question",
 | 
				
			||||||
    "core.login.selectacountry": "Select a country",
 | 
					    "core.login.selectacountry": "Select a country",
 | 
				
			||||||
 | 
				
			|||||||
@ -12,6 +12,8 @@
 | 
				
			|||||||
    "createuserandpass": "Choose your username and password",
 | 
					    "createuserandpass": "Choose your username and password",
 | 
				
			||||||
    "credentialsdescription": "Please provide your username and password to log in.",
 | 
					    "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>",
 | 
					    "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",
 | 
					    "emailnotmatch": "Emails do not match",
 | 
				
			||||||
    "enterthewordsabove": "Enter the words above",
 | 
					    "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",
 | 
					    "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",
 | 
					    "missingfirstname": "Missing given name",
 | 
				
			||||||
    "missinglastname": "Missing surname",
 | 
					    "missinglastname": "Missing surname",
 | 
				
			||||||
    "mobileservicesnotenabled": "Mobile access is not enabled on your site. Please contact your site administrator if you think it should be enabled.",
 | 
					    "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",
 | 
					    "newaccount": "New account",
 | 
				
			||||||
    "newsitedescription": "Please enter the URL of your Moodle site. Note that it might not be configured to work with this app.",
 | 
					    "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.",
 | 
					    "notloggedin": "You need to be logged in.",
 | 
				
			||||||
@ -66,6 +69,7 @@
 | 
				
			|||||||
    "reconnect": "Reconnect",
 | 
					    "reconnect": "Reconnect",
 | 
				
			||||||
    "reconnectdescription": "Your authentication token is invalid or has expired. You have to reconnect to the site.",
 | 
					    "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.",
 | 
					    "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:",
 | 
					    "searchby": "Search by:",
 | 
				
			||||||
    "security_question": "Security question",
 | 
					    "security_question": "Security question",
 | 
				
			||||||
    "selectacountry": "Select a country",
 | 
					    "selectacountry": "Select a country",
 | 
				
			||||||
 | 
				
			|||||||
@ -228,7 +228,7 @@ export class CoreLoginCredentialsPage {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }).catch((error) => {
 | 
					        }).catch((error) => {
 | 
				
			||||||
            this.loginHelper.treatUserTokenError(siteUrl, error);
 | 
					            this.loginHelper.treatUserTokenError(siteUrl, error, username, password);
 | 
				
			||||||
        }).finally(() => {
 | 
					        }).finally(() => {
 | 
				
			||||||
            modal.dismiss();
 | 
					            modal.dismiss();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
				
			|||||||
@ -154,7 +154,7 @@ export class CoreLoginReconnectPage {
 | 
				
			|||||||
                });
 | 
					                });
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }).catch((error) => {
 | 
					        }).catch((error) => {
 | 
				
			||||||
            this.loginHelper.treatUserTokenError(siteUrl, error);
 | 
					            this.loginHelper.treatUserTokenError(siteUrl, error, username, password);
 | 
				
			||||||
        }).finally(() => {
 | 
					        }).finally(() => {
 | 
				
			||||||
            modal.dismiss();
 | 
					            modal.dismiss();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
				
			|||||||
@ -92,7 +92,7 @@ export class CoreLoginSitePage {
 | 
				
			|||||||
                    this.domUtils.showErrorModal(error);
 | 
					                    this.domUtils.showErrorModal(error);
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            }, (error) => {
 | 
					            }, (error) => {
 | 
				
			||||||
                this.loginHelper.treatUserTokenError(siteData.url, error);
 | 
					                this.loginHelper.treatUserTokenError(siteData.url, error, siteData.username, siteData.password);
 | 
				
			||||||
            }).finally(() => {
 | 
					            }).finally(() => {
 | 
				
			||||||
                modal.dismiss();
 | 
					                modal.dismiss();
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
				
			|||||||
@ -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.
 | 
					     * 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 {string} siteUrl Site URL to construct change password URL.
 | 
				
			||||||
     * @param {any} error Error object containing errorcode and error message.
 | 
					     * @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') {
 | 
					        if (error.errorcode == 'forcepasswordchangenotice') {
 | 
				
			||||||
            this.openChangePassword(siteUrl, this.textUtils.getErrorMessageFromError(error));
 | 
					            this.openChangePassword(siteUrl, this.textUtils.getErrorMessageFromError(error));
 | 
				
			||||||
 | 
					        } else if (error.errorcode == 'usernotconfirmed') {
 | 
				
			||||||
 | 
					            this.showNotConfirmedModal(siteUrl, undefined, username, password);
 | 
				
			||||||
        } else if (error.errorcode == 'legacymoodleversion') {
 | 
					        } else if (error.errorcode == 'legacymoodleversion') {
 | 
				
			||||||
            this.showLegacyNoticeModal(this.textUtils.getErrorMessageFromError(error));
 | 
					            this.showLegacyNoticeModal(this.textUtils.getErrorMessageFromError(error));
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user