home.component.ts 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Component, OnInit } from '@angular/core';
  2. import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
  3. import { JhiEventManager } from 'ng-jhipster';
  4. import { LoginModalService, Principal, Account } from 'app/core';
  5. @Component({
  6. selector: 'jhi-home',
  7. templateUrl: './home.component.html',
  8. styleUrls: ['home.scss']
  9. })
  10. export class HomeComponent implements OnInit {
  11. account: Account;
  12. modalRef: NgbModalRef;
  13. constructor(private principal: Principal, private loginModalService: LoginModalService, private eventManager: JhiEventManager) {}
  14. ngOnInit() {
  15. this.principal.identity().then(account => {
  16. this.account = account;
  17. });
  18. this.registerAuthenticationSuccess();
  19. }
  20. registerAuthenticationSuccess() {
  21. this.eventManager.subscribe('authenticationSuccess', message => {
  22. this.principal.identity().then(account => {
  23. this.account = account;
  24. });
  25. });
  26. }
  27. isAuthenticated() {
  28. return this.principal.isAuthenticated();
  29. }
  30. login() {
  31. this.modalRef = this.loginModalService.open();
  32. }
  33. }