Merge pull request #2143 from dpalou/MOBILE-3195

MOBILE-3195 login: Allow to disable forgotten password
main
Juan Leyva 2019-11-07 17:46:58 +01:00 committed by GitHub
commit e2dc900f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 17 deletions

View File

@ -36,7 +36,7 @@
</form>
<!-- Forgotten password button. -->
<div padding-top class="core-login-forgotten-password">
<div *ngIf="showForgottenPassword" padding-top class="core-login-forgotten-password">
<button ion-button block text-wrap color="light" (click)="forgottenPassword()">{{ 'core.login.forgotten' | translate }}</button>
</div>

View File

@ -43,6 +43,7 @@ export class CoreLoginCredentialsPage {
pageLoaded = false;
isBrowserSSO = false;
isFixedUrlSet = false;
showForgottenPassword = true;
protected siteConfig;
protected eventThrown = false;
@ -50,9 +51,14 @@ export class CoreLoginCredentialsPage {
protected siteId: string;
protected urlToOpen: string;
constructor(private navCtrl: NavController, navParams: NavParams, fb: FormBuilder, private appProvider: CoreAppProvider,
private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider,
private domUtils: CoreDomUtilsProvider, private translate: TranslateService,
constructor(private navCtrl: NavController,
navParams: NavParams,
fb: FormBuilder,
private appProvider: CoreAppProvider,
private sitesProvider: CoreSitesProvider,
private loginHelper: CoreLoginHelperProvider,
private domUtils: CoreDomUtilsProvider,
private translate: TranslateService,
private eventsProvider: CoreEventsProvider) {
this.siteUrl = navParams.get('siteUrl');
@ -149,9 +155,13 @@ export class CoreLoginCredentialsPage {
this.siteName = CoreConfigConstants.sitename ? CoreConfigConstants.sitename : this.siteConfig.sitename;
this.logoUrl = this.siteConfig.logourl || this.siteConfig.compactlogourl;
this.authInstructions = this.siteConfig.authinstructions || this.translate.instant('core.login.loginsteps');
this.canSignup = this.siteConfig.registerauth == 'email' && !this.loginHelper.isEmailSignupDisabled(this.siteConfig);
this.identityProviders = this.loginHelper.getValidIdentityProviders(this.siteConfig);
const disabledFeatures = this.loginHelper.getDisabledFeatures(this.siteConfig);
this.canSignup = this.siteConfig.registerauth == 'email' &&
!this.loginHelper.isEmailSignupDisabled(this.siteConfig, disabledFeatures);
this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(this.siteConfig, disabledFeatures);
if (!this.eventThrown && !this.viewLeft) {
this.eventThrown = true;
this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_CHECKED, { config: this.siteConfig });

View File

@ -50,7 +50,7 @@
</ion-list>
<!-- Forgotten password button. -->
<div padding-top class="core-login-forgotten-password">
<div *ngIf="showForgottenPassword" padding-top class="core-login-forgotten-password">
<button ion-button block text-wrap color="light" (click)="forgottenPassword()">{{ 'core.login.forgotten' | translate }}</button>
</div>

View File

@ -36,6 +36,7 @@ export class CoreLoginReconnectPage {
logoUrl: string;
identityProviders: any[];
site: any;
showForgottenPassword = true;
protected infoSiteUrl: string;
protected pageName: string;
@ -44,9 +45,13 @@ export class CoreLoginReconnectPage {
protected isLoggedOut: boolean;
protected siteId: string;
constructor(private navCtrl: NavController, navParams: NavParams, fb: FormBuilder, private appProvider: CoreAppProvider,
private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider,
private domUtils: CoreDomUtilsProvider) {
constructor(private navCtrl: NavController,
navParams: NavParams,
fb: FormBuilder,
private appProvider: CoreAppProvider,
private sitesProvider: CoreSitesProvider,
private loginHelper: CoreLoginHelperProvider,
private domUtils: CoreDomUtilsProvider) {
const currentSite = this.sitesProvider.getCurrentSite();
@ -69,6 +74,7 @@ export class CoreLoginReconnectPage {
ionViewDidLoad(): void {
if (this.siteConfig) {
this.identityProviders = this.loginHelper.getValidIdentityProviders(this.siteConfig);
this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(this.siteConfig);
}
this.sitesProvider.getSite(this.siteId).then((site) => {
@ -87,9 +93,10 @@ export class CoreLoginReconnectPage {
// Check logoURL if user avatar is not set.
if (this.site.avatar.startsWith(site.infos.siteurl + '/theme/image.php')) {
this.site.avatar = false;
this.logoUrl = config.logourl || config.compactlogourl;
}
this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(config);
}).catch(() => {
this.cancel();
});

View File

@ -322,6 +322,21 @@ export class CoreLoginHelperProvider {
});
}
/**
* Get disabled features from a site public config.
*
* @param config Site public config.
* @return Disabled features.
*/
getDisabledFeatures(config: any): string {
const disabledFeatures = config && config.tool_mobile_disabledfeatures;
if (!disabledFeatures) {
return '';
}
return this.textUtils.treatDisabledFeatures(disabledFeatures);
}
/**
* Builds an object with error messages for some common errors.
* Please notice that this function doesn't support all possible error types.
@ -555,17 +570,27 @@ export class CoreLoginHelperProvider {
* Given a site public config, check if email signup is disabled.
*
* @param config Site public config.
* @param disabledFeatures List of disabled features already treated. If not provided it will be calculated.
* @return Whether email signup is disabled.
*/
isEmailSignupDisabled(config: any): boolean {
let disabledFeatures = config && config.tool_mobile_disabledfeatures;
if (!disabledFeatures) {
return false;
isEmailSignupDisabled(config?: any, disabledFeatures?: string): boolean {
return this.isFeatureDisabled('CoreLoginEmailSignup', config, disabledFeatures);
}
/**
* Given a site public config, check if a certian feature is disabled.
*
* @param feature Feature to check.
* @param config Site public config.
* @param disabledFeatures List of disabled features already treated. If not provided it will be calculated.
* @return Whether email signup is disabled.
*/
isFeatureDisabled(feature: string, config?: any, disabledFeatures?: string): boolean {
if (typeof disabledFeatures == 'undefined') {
disabledFeatures = this.getDisabledFeatures(config);
}
disabledFeatures = this.textUtils.treatDisabledFeatures(disabledFeatures);
const regEx = new RegExp('(,|^)CoreLoginEmailSignup(,|$)', 'g');
const regEx = new RegExp('(,|^)' + feature + '(,|$)', 'g');
return !!disabledFeatures.match(regEx);
}
@ -583,6 +608,17 @@ export class CoreLoginHelperProvider {
return !!CoreConfigConstants.siteurl;
}
/**
* Given a site public config, check if forgotten password is disabled.
*
* @param config Site public config.
* @param disabledFeatures List of disabled features already treated. If not provided it will be calculated.
* @return Whether it's disabled.
*/
isForgottenPasswordDisabled(config?: any, disabledFeatures?: string): boolean {
return this.isFeatureDisabled('NoDelegate_ForgottenPassword', config, disabledFeatures);
}
/**
* Check if current site is logged out, triggering mmCoreEventSessionExpired if it is.
*