Skip to content

Commit

Permalink
Hide registration feature behind a feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Rusakov committed Nov 20, 2024
1 parent 4f76d6f commit a6f4442
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<mat-icon>input</mat-icon>
<span i18n="@@account.log_in">S'authentifier</span>
</button>
<button mat-button color="primary" [routerLink]="['auth/register']">
<button mat-button *ngIf="isRegistrationEnabled()" color="primary" [routerLink]="['auth/register']">
<mat-icon>person_add</mat-icon>
<span i18n="@@account.create_account">Créer un compte</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Store} from '@ngrx/store';
import {AppState, getUser, isLoggedIn} from '../../_store';
import * as fromAuth from '../../_store/auth/auth.action';
import * as fromCart from '../../_store/cart/cart.action';
import { ConfigService } from 'src/app/_services/config.service';

@Component({
selector: 'gs2-account-overlay',
Expand All @@ -16,7 +17,7 @@ export class AccountOverlayComponent implements OnInit {
isLoggedIn$ = this.store.select(isLoggedIn);
user$ = this.store.select(getUser);

constructor(private store: Store<AppState>) {
constructor(private store: Store<AppState>, private readonly configService: ConfigService) {
}

ngOnInit(): void {
Expand All @@ -26,4 +27,8 @@ export class AccountOverlayComponent implements OnInit {
this.store.dispatch(fromCart.deleteOrder());
this.store.dispatch(fromAuth.logout());
}

public isRegistrationEnabled():boolean {
return (this.configService.config?.features.indexOf('registration') ?? -1) >= 0;
}
}
1 change: 1 addition & 0 deletions src/app/_models/IConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IConfig {
resolutions: number[];
epsg: string;
pageformats: Array<IPageFormat>;
features: string[];
oidcConfig: OpenIdConfiguration;
}

Expand Down
1 change: 0 additions & 1 deletion src/app/_services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {ICredentials, IIdentity} from '../_models/IIdentity';
import {catchError, map, switchMap} from 'rxjs/operators';
import {IMetadata} from '../_models/IMetadata';
import {IUser, IUserChangeResponse, IUserToPost} from '../_models/IUser';
import { LoginResponse } from 'angular-auth-oidc-client';

@Injectable({
providedIn: 'root'
Expand Down
156 changes: 80 additions & 76 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import {BrowserModule} from '@angular/platform-browser';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, APP_INITIALIZER, LOCALE_ID, DEFAULT_CURRENCY_CODE, Inject } from '@angular/core';
import { registerLocaleData } from '@angular/common';
import localeCH from '@angular/common/locales/fr-CH';

import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {ConfigService} from './_services/config.service';
import {CustomIconService} from './_services/custom-icon.service';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ConfigService } from './_services/config.service';
import { CustomIconService } from './_services/custom-icon.service';
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import {AccountOverlayComponent} from './_components/account-overlay/account-overlay.component';
import {HelpOverlayComponent} from './_components/help-overlay/help-overlay.component';
import {MatRippleModule} from '@angular/material/core';
import {MatBadgeModule} from '@angular/material/badge';
import {CartOverlayComponent} from './_components/cart-overlay/cart-overlay.component';
import {StoreModule, Store} from '@ngrx/store';
import {EffectsModule} from '@ngrx/effects';
import {AuthEffects} from './_store/auth/auth.effects';
import {reducers, metaReducers, AppState, getUser} from './_store';
import {TokenInterceptor} from './_interceptors/tokenInterceptor';
import {MatMenuModule} from '@angular/material/menu';
import {MatIconModule} from '@angular/material/icon';
import {MatDividerModule} from '@angular/material/divider';
import {MatToolbarModule} from '@angular/material/toolbar';
import {MatButtonModule} from '@angular/material/button';
import {MatDialogModule} from '@angular/material/dialog';
import {MatSnackBarModule} from '@angular/material/snack-bar';
import {ErrorInterceptor} from './_interceptors/errorInterceptor';
import {MatTooltipModule} from '@angular/material/tooltip';
import {OverlayContainer} from '@angular/cdk/overlay';
import {ActivatedRoute} from '@angular/router';
import {CartEffects} from './_store/cart/cart.effects';
import { AccountOverlayComponent } from './_components/account-overlay/account-overlay.component';
import { HelpOverlayComponent } from './_components/help-overlay/help-overlay.component';
import { MatRippleModule } from '@angular/material/core';
import { MatBadgeModule } from '@angular/material/badge';
import { CartOverlayComponent } from './_components/cart-overlay/cart-overlay.component';
import { StoreModule, Store } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import { AuthEffects } from './_store/auth/auth.effects';
import { reducers, metaReducers, AppState, getUser } from './_store';
import { TokenInterceptor } from './_interceptors/tokenInterceptor';
import { MatMenuModule } from '@angular/material/menu';
import { MatIconModule } from '@angular/material/icon';
import { MatDividerModule } from '@angular/material/divider';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { ErrorInterceptor } from './_interceptors/errorInterceptor';
import { MatTooltipModule } from '@angular/material/tooltip';
import { OverlayContainer } from '@angular/cdk/overlay';
import { ActivatedRoute } from '@angular/router';
import { CartEffects } from './_store/cart/cart.effects';
import * as fromAuth from './_store/auth/auth.action';
import {CommonModule} from '@angular/common';
import { CommonModule } from '@angular/common';
import { OidcAuthConfigModule } from './auth/oidc-auth-config.module';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';

registerLocaleData(localeCH);

export function initializeApp(configService: ConfigService, store: Store<AppState>) {
return () => configService.load().then(() => {
store.select(getUser).subscribe(user => {
if (user && user.tokenRefresh) {
store.dispatch(fromAuth.refreshToken({token: user.tokenRefresh}));
}
});
})
store.select(getUser).subscribe(user => {
if (user && user.tokenRefresh) {
store.dispatch(fromAuth.refreshToken({ token: user.tokenRefresh }));
}
});
})
}

const MODULES = [
Expand All @@ -62,47 +62,51 @@ const MODULES = [
MatTooltipModule
];

@NgModule({ declarations: [
AppComponent,
AccountOverlayComponent,
HelpOverlayComponent,
CartOverlayComponent,
],
bootstrap: [AppComponent], imports: [BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
MODULES,
StoreModule.forRoot(reducers, { metaReducers }),
EffectsModule.forRoot([AuthEffects, CartEffects]),
OidcAuthConfigModule], providers: [
{
provide: APP_INITIALIZER,
useFactory: initializeApp,
deps: [ConfigService, [new Inject(Store)]],
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptor,
multi: true,
},
{
provide: HTTP_INTERCEPTORS,
useClass: ErrorInterceptor,
multi: true,
},
{
provide: LOCALE_ID,
useValue: 'fr-CH'
},
{
provide: DEFAULT_CURRENCY_CODE,
useValue: 'CHF'
},
CustomIconService,
provideHttpClient(withInterceptorsFromDi()),
provideAnimationsAsync()
] })
@NgModule({
declarations: [
AppComponent,
AccountOverlayComponent,
HelpOverlayComponent,
CartOverlayComponent,
],
bootstrap: [AppComponent],
imports: [BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
MODULES,
StoreModule.forRoot(reducers, { metaReducers }),
EffectsModule.forRoot([AuthEffects, CartEffects]),
OidcAuthConfigModule
], providers: [
{
provide: APP_INITIALIZER,
useFactory: initializeApp,
deps: [ConfigService, [new Inject(Store)]],
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptor,
multi: true,
},
{
provide: HTTP_INTERCEPTORS,
useClass: ErrorInterceptor,
multi: true,
},
{
provide: LOCALE_ID,
useValue: 'fr-CH'
},
{
provide: DEFAULT_CURRENCY_CODE,
useValue: 'CHF'
},
CustomIconService,
provideHttpClient(withInterceptorsFromDi()),
provideAnimationsAsync()
]
})
export class AppModule {
constructor(overlayContainer: OverlayContainer, route: ActivatedRoute) {
route.queryParams.subscribe(res => {
Expand Down
9 changes: 7 additions & 2 deletions src/app/auth/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import {Store} from '@ngrx/store';
import {IIdentity} from '../../_models/IIdentity';
import {ApiService} from '../../_services/api.service';
import {map} from 'rxjs/operators';
import {Router} from '@angular/router';
import {ActivatedRoute, Route, Router} from '@angular/router';
import {MatSnackBar} from '@angular/material/snack-bar';
import {StepperSelectionEvent} from '@angular/cdk/stepper';
import {PHONE_REGEX, IDE_REGEX} from '../../_helpers/regex';
import {ConstantsService} from '../../constants.service';
import { ConfigService } from 'src/app/_services/config.service';

@Component({
selector: 'gs2-register',
Expand Down Expand Up @@ -126,10 +127,14 @@ export class RegisterComponent implements OnInit, AfterViewInit {
return this.formCredentials.get('passwords')?.get('passwordConfirm');
}

constructor(private store: Store<AppState>, private apiService: ApiService,
constructor(private apiService: ApiService,
private readonly configService: ConfigService,
private router: Router,
private snackBar: MatSnackBar
) {
if ((this.configService.config?.features.indexOf('registration') ?? -1) == -1) {
this.router.navigate(["/"]);
};
}

private static passwordMatchValidator(g: UntypedFormGroup) {
Expand Down
1 change: 1 addition & 0 deletions src/assets/configs/config.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"height": 1189
}
],
"features": ["oidc", "registration"],
"oidcConfig": {
"authority": "${OIDC_OP_BASE_URL}",
"redirectUrl": "${FRONTEND_BASE_URL}/auth/oidc",
Expand Down

0 comments on commit a6f4442

Please sign in to comment.