MOBILE-4034 login: Close IAB after user changes password
parent
00170e090c
commit
94444fbc96
|
@ -12,13 +12,15 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnDestroy } from '@angular/core';
|
||||
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreLoginHelper } from '@features/login/services/login-helper';
|
||||
import { Translate } from '@singletons';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreEventObserver, CoreEvents } from '@singletons/events';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
|
||||
/**
|
||||
* Page that shows instructions to change the password.
|
||||
|
@ -27,11 +29,14 @@ import { CoreNavigator } from '@services/navigator';
|
|||
selector: 'page-core-login-change-password',
|
||||
templateUrl: 'change-password.html',
|
||||
})
|
||||
export class CoreLoginChangePasswordPage {
|
||||
export class CoreLoginChangePasswordPage implements OnDestroy {
|
||||
|
||||
changingPassword = false;
|
||||
logoutLabel: string;
|
||||
|
||||
protected urlLoadedObserver?: CoreEventObserver;
|
||||
protected browserClosedObserver?: CoreEventObserver;
|
||||
|
||||
constructor() {
|
||||
this.logoutLabel = CoreLoginHelper.getLogoutLabel();
|
||||
}
|
||||
|
@ -57,6 +62,7 @@ export class CoreLoginChangePasswordPage {
|
|||
true,
|
||||
);
|
||||
this.changingPassword = true;
|
||||
this.detectPasswordChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,4 +81,37 @@ export class CoreLoginChangePasswordPage {
|
|||
this.changingPassword = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to detect if the user changed password in browser.
|
||||
*/
|
||||
detectPasswordChanged(): void {
|
||||
if (this.urlLoadedObserver) {
|
||||
// Already listening (shouldn't happen).
|
||||
return;
|
||||
}
|
||||
|
||||
this.urlLoadedObserver = CoreEvents.on(CoreEvents.IAB_LOAD_START, (event) => {
|
||||
if (event.url.match(/\/login\/change_password\.php.*return=1/)) {
|
||||
// Password should have changed.
|
||||
CoreUtils.closeInAppBrowser();
|
||||
this.login();
|
||||
}
|
||||
});
|
||||
|
||||
this.browserClosedObserver = CoreEvents.on(CoreEvents.IAB_EXIT, () => {
|
||||
this.urlLoadedObserver?.off();
|
||||
this.browserClosedObserver?.off();
|
||||
delete this.urlLoadedObserver;
|
||||
delete this.browserClosedObserver;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ngOnDestroy(): void {
|
||||
this.urlLoadedObserver?.off();
|
||||
this.browserClosedObserver?.off();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue