Commit bfa32587 authored by Barbora Kompišová's avatar Barbora Kompišová
Browse files

cleanup

parent d16c2194
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -15,7 +15,6 @@ export class AdminGuard implements CanActivate {
    if (loggedInUser.is_admin) {
    if (loggedInUser.is_admin) {
      return true;
      return true;
    }
    }
    // todo: flash access denied
    this.router.navigateByUrl('/dashboard').then(() => {
    this.router.navigateByUrl('/dashboard').then(() => {
      this.flashMessagesService.show(`You are not authorized to access ${next.url}.`, {cssClass: 'alert-danger'});
      this.flashMessagesService.show(`You are not authorized to access ${next.url}.`, {cssClass: 'alert-danger'});
    });
    });
+2 −31
Original line number Original line Diff line number Diff line
import {Injectable} from '@angular/core';
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {FlashMessagesService} from 'angular2-flash-messages/module/flash-messages.service';
import {User} from '../shared/models/models';
import {User} from '../shared/models/models';
import {Observable} from 'rxjs/Observable';
import {Observable} from 'rxjs/Observable';
import {AuthService} from './auth.service';
import {AuthService} from './auth.service';
import {of} from 'rxjs/observable/of';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/catch';


@Injectable()
@Injectable()
export class LoggedInUserResolver implements Resolve<User> {
export class LoggedInUserResolver implements Resolve<User> {


  constructor(private auth: AuthService, private router: Router, private flashMessagesService: FlashMessagesService) {
  constructor(private auth: AuthService) {
  }
  }


  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<User> {
  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<User> {
    // TODO: handle error correctly (in service?)
    return this.auth.loggedInUser.take(1);
    return this.auth.loggedInUser.take(1);
    /* error handling
    .catch(
      (error: any) => {
        console.log('error getting loggedInUser: ', error);
        this.router.navigateByUrl('/login').then(
          () => {
            console.log('loggedInUser not found in auth service.');
            this.flashMessagesService.show('You are not logged in.');
          }, (err: any) => {
            console.log('Could not navigate to login: ', err);
          });
        return of(null);
      });*/
    /* permission loading
    return this.auth.loggedInUser.take(1).map(
      user => {
        this.auth.loadPermissionsForUser(user).map(
          permissions => {
            user.permissions = permissions;
            return of(user);
          }
        ).finally(() => {
          return of(user);
        });
    });
     */
  }
  }
}
}
+0 −6
Original line number Original line Diff line number Diff line
@@ -47,10 +47,4 @@ export class SideMenuComponent implements OnInit, OnDestroy {
  }
  }


}
}
// TODO: move userService, maybe others, to shared module
/*
https://angularfirebase.com/lessons/bootstrap-4-collapsable-navbar-work-with-angular/
https://angularfirebase.com/lessons/sharing-data-between-angular-components-four-methods/#Unrelated-Components-Sharing-Data-with-a-Service
https://blog.thoughtram.io/angular/2016/10/10/resolving-route-data-in-angular-2.html
*/