forked from CIT/Vmeda.Online
		
	MOBILE-3195 login: Allow to disable forgotten password
This commit is contained in:
		
							parent
							
								
									dc35bc914f
								
							
						
					
					
						commit
						d8a1d2d956
					
				| @ -36,7 +36,7 @@ | |||||||
|             </form> |             </form> | ||||||
| 
 | 
 | ||||||
|             <!-- Forgotten password button. --> |             <!-- 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> |                 <button ion-button block text-wrap color="light" (click)="forgottenPassword()">{{ 'core.login.forgotten' | translate }}</button> | ||||||
|             </div> |             </div> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -43,6 +43,7 @@ export class CoreLoginCredentialsPage { | |||||||
|     pageLoaded = false; |     pageLoaded = false; | ||||||
|     isBrowserSSO = false; |     isBrowserSSO = false; | ||||||
|     isFixedUrlSet = false; |     isFixedUrlSet = false; | ||||||
|  |     showForgottenPassword = true; | ||||||
| 
 | 
 | ||||||
|     protected siteConfig; |     protected siteConfig; | ||||||
|     protected eventThrown = false; |     protected eventThrown = false; | ||||||
| @ -50,9 +51,14 @@ export class CoreLoginCredentialsPage { | |||||||
|     protected siteId: string; |     protected siteId: string; | ||||||
|     protected urlToOpen: string; |     protected urlToOpen: string; | ||||||
| 
 | 
 | ||||||
|     constructor(private navCtrl: NavController, navParams: NavParams, fb: FormBuilder, private appProvider: CoreAppProvider, |     constructor(private navCtrl: NavController, | ||||||
|             private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, |             navParams: NavParams, | ||||||
|             private domUtils: CoreDomUtilsProvider, private translate: TranslateService, |             fb: FormBuilder, | ||||||
|  |             private appProvider: CoreAppProvider, | ||||||
|  |             private sitesProvider: CoreSitesProvider, | ||||||
|  |             private loginHelper: CoreLoginHelperProvider, | ||||||
|  |             private domUtils: CoreDomUtilsProvider, | ||||||
|  |             private translate: TranslateService, | ||||||
|             private eventsProvider: CoreEventsProvider) { |             private eventsProvider: CoreEventsProvider) { | ||||||
| 
 | 
 | ||||||
|         this.siteUrl = navParams.get('siteUrl'); |         this.siteUrl = navParams.get('siteUrl'); | ||||||
| @ -149,9 +155,13 @@ export class CoreLoginCredentialsPage { | |||||||
|             this.siteName = CoreConfigConstants.sitename ? CoreConfigConstants.sitename : this.siteConfig.sitename; |             this.siteName = CoreConfigConstants.sitename ? CoreConfigConstants.sitename : this.siteConfig.sitename; | ||||||
|             this.logoUrl = this.siteConfig.logourl || this.siteConfig.compactlogourl; |             this.logoUrl = this.siteConfig.logourl || this.siteConfig.compactlogourl; | ||||||
|             this.authInstructions = this.siteConfig.authinstructions || this.translate.instant('core.login.loginsteps'); |             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); |             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) { |             if (!this.eventThrown && !this.viewLeft) { | ||||||
|                 this.eventThrown = true; |                 this.eventThrown = true; | ||||||
|                 this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_CHECKED, { config: this.siteConfig }); |                 this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_CHECKED, { config: this.siteConfig }); | ||||||
|  | |||||||
| @ -50,7 +50,7 @@ | |||||||
|         </ion-list> |         </ion-list> | ||||||
| 
 | 
 | ||||||
|         <!-- Forgotten password button. --> |         <!-- 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> |             <button ion-button block text-wrap color="light" (click)="forgottenPassword()">{{ 'core.login.forgotten' | translate }}</button> | ||||||
|         </div> |         </div> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,6 +36,7 @@ export class CoreLoginReconnectPage { | |||||||
|     logoUrl: string; |     logoUrl: string; | ||||||
|     identityProviders: any[]; |     identityProviders: any[]; | ||||||
|     site: any; |     site: any; | ||||||
|  |     showForgottenPassword = true; | ||||||
| 
 | 
 | ||||||
|     protected infoSiteUrl: string; |     protected infoSiteUrl: string; | ||||||
|     protected pageName: string; |     protected pageName: string; | ||||||
| @ -44,8 +45,12 @@ export class CoreLoginReconnectPage { | |||||||
|     protected isLoggedOut: boolean; |     protected isLoggedOut: boolean; | ||||||
|     protected siteId: string; |     protected siteId: string; | ||||||
| 
 | 
 | ||||||
|     constructor(private navCtrl: NavController, navParams: NavParams, fb: FormBuilder, private appProvider: CoreAppProvider, |     constructor(private navCtrl: NavController, | ||||||
|         private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, |             navParams: NavParams, | ||||||
|  |             fb: FormBuilder, | ||||||
|  |             private appProvider: CoreAppProvider, | ||||||
|  |             private sitesProvider: CoreSitesProvider, | ||||||
|  |             private loginHelper: CoreLoginHelperProvider, | ||||||
|             private domUtils: CoreDomUtilsProvider) { |             private domUtils: CoreDomUtilsProvider) { | ||||||
| 
 | 
 | ||||||
|         const currentSite = this.sitesProvider.getCurrentSite(); |         const currentSite = this.sitesProvider.getCurrentSite(); | ||||||
| @ -69,6 +74,7 @@ export class CoreLoginReconnectPage { | |||||||
|     ionViewDidLoad(): void { |     ionViewDidLoad(): void { | ||||||
|         if (this.siteConfig) { |         if (this.siteConfig) { | ||||||
|             this.identityProviders = this.loginHelper.getValidIdentityProviders(this.siteConfig); |             this.identityProviders = this.loginHelper.getValidIdentityProviders(this.siteConfig); | ||||||
|  |             this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(this.siteConfig); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.sitesProvider.getSite(this.siteId).then((site) => { |         this.sitesProvider.getSite(this.siteId).then((site) => { | ||||||
| @ -87,9 +93,10 @@ export class CoreLoginReconnectPage { | |||||||
|                     // Check logoURL if user avatar is not set.
 |                     // Check logoURL if user avatar is not set.
 | ||||||
|                     if (this.site.avatar.startsWith(site.infos.siteurl + '/theme/image.php')) { |                     if (this.site.avatar.startsWith(site.infos.siteurl + '/theme/image.php')) { | ||||||
|                         this.site.avatar = false; |                         this.site.avatar = false; | ||||||
| 
 |  | ||||||
|                         this.logoUrl = config.logourl || config.compactlogourl; |                         this.logoUrl = config.logourl || config.compactlogourl; | ||||||
|                     } |                     } | ||||||
|  | 
 | ||||||
|  |                     this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(config); | ||||||
|                 }).catch(() => { |                 }).catch(() => { | ||||||
|                     this.cancel(); |                     this.cancel(); | ||||||
|                 }); |                 }); | ||||||
|  | |||||||
| @ -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. |      * Builds an object with error messages for some common errors. | ||||||
|      * Please notice that this function doesn't support all possible error types. |      * 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. |      * Given a site public config, check if email signup is disabled. | ||||||
|      * |      * | ||||||
|      * @param config Site public config. |      * @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. |      * @return Whether email signup is disabled. | ||||||
|      */ |      */ | ||||||
|     isEmailSignupDisabled(config: any): boolean { |     isEmailSignupDisabled(config?: any, disabledFeatures?: string): boolean { | ||||||
|         let disabledFeatures = config && config.tool_mobile_disabledfeatures; |         return this.isFeatureDisabled('CoreLoginEmailSignup', config, disabledFeatures); | ||||||
|         if (!disabledFeatures) { |  | ||||||
|             return false; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|         disabledFeatures = this.textUtils.treatDisabledFeatures(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); | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         const regEx = new RegExp('(,|^)CoreLoginEmailSignup(,|$)', 'g'); |         const regEx = new RegExp('(,|^)' + feature + '(,|$)', 'g'); | ||||||
| 
 | 
 | ||||||
|         return !!disabledFeatures.match(regEx); |         return !!disabledFeatures.match(regEx); | ||||||
|     } |     } | ||||||
| @ -583,6 +608,17 @@ export class CoreLoginHelperProvider { | |||||||
|         return !!CoreConfigConstants.siteurl; |         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. |      * Check if current site is logged out, triggering mmCoreEventSessionExpired if it is. | ||||||
|      * |      * | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user