login-button.component.ts
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Component, OnInit } from '@angular/core';
import {MatDialog, MatDialogConfig} from '@angular/material';
import {LoginComponent} from '../login-component/login.component';
import {Router} from '@angular/router';
import {SessionServiceService} from '../../../shared/services/session-service.service';
import {EventUser} from '../../../shared/models/event-user.model';
import {User} from '../../../shared/models/user.model';
@Component({
selector: 'moya-login-button',
templateUrl: './login-button.component.html',
styleUrls: ['./login-button.component.css']
})
export class LoginButtonComponent implements OnInit {
loggedIn = false;
currentUser: User = null;
constructor(private router: Router, private dialog: MatDialog, private sessionService: SessionServiceService) {
this.sessionService.getCurrentUser().subscribe((user: User) => {
this.loggedIn = !user.isAnonymous();
this.currentUser = user;
});
}
logout() {
this.sessionService.logout();
}
ngOnInit() { }
openLoginDialog(): void {
const conf = new MatDialogConfig();
conf.autoFocus = true;
/*conf.height = "800px";
conf.width = "500px";*/
const dialogRef = this.dialog.open(LoginComponent, conf);
dialogRef.componentInstance.loginEvent.subscribe((success) => {
if (success) {
dialogRef.close();
} else {
dialogRef.close();
this.router.navigateByUrl('/login');
}
});
}
}