Skip to content

Commit

Permalink
Fix Calendar and Base Auth
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanF committed Oct 15, 2023
1 parent 8479cc4 commit aadd676
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
12 changes: 7 additions & 5 deletions src/app/@cyborg/auth/server.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Inject, Injectable, Injector } from '@angular/core';
import { Injectable, Injector} from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
import {NB_AUTH_TOKEN_INTERCEPTOR_FILTER, NbAuthService} from '@nebular/auth';
import {NbAuthService} from '@nebular/auth';

@Injectable()
export class ServerInterceptor implements HttpInterceptor {

constructor(private injector: Injector,
@Inject(NB_AUTH_TOKEN_INTERCEPTOR_FILTER) protected filter) {
constructor(private injector: Injector) {
}

protected get authService(): NbAuthService {
Expand All @@ -16,7 +15,10 @@ export class ServerInterceptor implements HttpInterceptor {

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const currentServer = localStorage.getItem('localServer');
if (!this.filter(req)) {
console.log(currentServer);
console.log(req.url);
console.log(req.url.startsWith('/api/v1/'));
if (req.url.startsWith('/api/v1/') && currentServer) {
req = req.clone({
url: currentServer + req.url
});
Expand Down
4 changes: 3 additions & 1 deletion src/app/@cyborg/auth/token.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export class TokenInterceptor implements HttpInterceptor {
}

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (!this.filter(req)) {
console.log(req.url);
console.log(req.url.indexOf('/api/v1/'));
if (req.url.includes('/api/v1/')) {
return this.authService.isAuthenticatedOrRefresh()
.pipe(
switchMap(authenticated => {
Expand Down
76 changes: 39 additions & 37 deletions src/app/@cyborg/components/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,52 @@ import {Observable, of} from 'rxjs';
import {map} from 'rxjs/operators';

@Component({
selector: 'cbg-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
selector: 'cbg-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent extends NbLoginComponent implements OnInit {
@ViewChild('cyborgServerInput') cyborgServerInput;
declare options: string[];
specificServer = false;
filteredOptions$: Observable<string[]>;
electronRunning = false;
export class LoginComponent extends NbLoginComponent implements OnInit {
@ViewChild('cyborgServerInput') cyborgServerInput;
declare options: string[];
specificServer = false;
filteredOptions$: Observable<string[]>;
electronRunning = false;

getFilteredOptions(value: string): Observable<string[]> {
return of(value).pipe(
map(filterString => this.filter(filterString)),
);
}

onChange() {
this.filteredOptions$ = this.getFilteredOptions(this.cyborgServerInput.nativeElement.value);
}
getFilteredOptions(value: string): Observable<string[]> {
return of(value).pipe(
map(filterString => this.filter(filterString)),
);
}

onSelectionChange($event) {
this.filteredOptions$ = this.getFilteredOptions($event);
}
onChange() {
this.filteredOptions$ = this.getFilteredOptions(this.cyborgServerInput.nativeElement.value);
}

ngOnInit(): void {
if (process && process.versions.hasOwnProperty('electron')) {
this.electronRunning = true;
onSelectionChange($event) {
this.filteredOptions$ = this.getFilteredOptions($event);
}
const savedServers = JSON.parse(localStorage.getItem('cyborgServers'));
this.options = [];
if (savedServers !== null && typeof savedServers === 'object' ) {
this.options = savedServers;

ngOnInit(): void {
if (process && process.versions.hasOwnProperty('electron')) {
this.electronRunning = true;
}
const savedServers = JSON.parse(localStorage.getItem('cyborgServers'));
this.options = [];
if (savedServers !== null && typeof savedServers === 'object') {
this.options = savedServers;
} else {
this.options = [];
}
}
}

checkServer(event): void {
if (!event) {
this.user.server = '';
checkServer(event): void {
if (!event) {
this.user.server = '';
}
}
}

private filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.options.filter(optionValue => optionValue.toLowerCase().includes(filterValue));
}
private filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.options.filter(optionValue => optionValue.toLowerCase().includes(filterValue));
}
}
4 changes: 2 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { DjangoPasswordAuthStrategy } from './@core/framework/auth/djangopassword/djangopassword-strategy';
import { HomeComponent } from './home/home.component';
import { TokenInterceptor } from './@cyborg/auth/token.interceptor';
import { ServerInterceptor } from './@cyborg/auth/server.interceptor';
import { ServerInterceptor} from './@cyborg/auth/server.interceptor';
import { NB_AUTH_TOKEN_INTERCEPTOR_FILTER } from '@nebular/auth';
import { CyborgModule } from './@cyborg/cyborg.module';
import { HttpXSRFInterceptor } from './@cyborg/auth/xsrf.interceptor';
Expand Down Expand Up @@ -76,7 +76,7 @@ import { HttpXSRFInterceptor } from './@cyborg/auth/xsrf.interceptor';
},
{
provide: NB_AUTH_TOKEN_INTERCEPTOR_FILTER,
useValue: (req) => req.url.indexOf('/api/v1/') !== 0,
useValue: (req) => req.url.indexOf('/api/v1/') !== -1,
}
],
bootstrap: [AppComponent],
Expand Down

0 comments on commit aadd676

Please sign in to comment.