Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ export class LoginComponent implements OnInit {

ngOnInit() {
this.getPlanetVersion();
this.configurationCheckService.checkConfiguration().subscribe(isOnline => {
this.online = isOnline;
});
}
this.configurationCheckService.checkConfiguration().subscribe(isOnline => {
if (!isOnline) {
this.online = 'off';
return;
}
this.online = isOnline;
});
}

getPlanetVersion() {
const opts = { responseType: 'text', withCredentials: false, headers: { 'Content-Type': 'text/plain' } };
Expand Down
22 changes: 13 additions & 9 deletions src/app/shared/configuration-check.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Injectable } from '@angular/core';
import { HttpParams } from '@angular/common/http';
import { Router } from '@angular/router';
import { environment } from '../../environments/environment';
import { CouchService } from './couchdb.service';
import { of } from 'rxjs';
import { tap, switchMap, catchError, map } from 'rxjs/operators';
import { switchMap, catchError, map, timeout } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -34,7 +35,10 @@ export class ConfigurationCheckService {
if (!data[0] || data[0].planetType === 'center') {
return of(false);
}
return this.couchService.get('', { domain: data[0].parentDomain });
return this.couchService.get('', { domain: data[0].parentDomain }).pipe(
timeout(3000),
catchError(() => of(false))
);
}),
map(data => {
this.online = (data) ? 'on' : 'off';
Expand All @@ -46,13 +50,13 @@ export class ConfigurationCheckService {
}

checkAdminExistence() {
return this.couchService.get('_users/_all_docs').pipe(
tap((data) => {
return true; // user can see data so there is no admin
}),
catchError((error) => {
return of(false); // user doesn't have permission so there is an admin
})
return this.couchService.get('_users/_all_docs', {
params: new HttpParams()
.set('limit', '1')
.set('include_docs', 'false')
}).pipe(
map(() => true),
catchError(() => of(false))
);
}

Expand Down
Loading