]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/menu/menu.component.ts
Add ability to limit user registrations
[github/Chocobozzz/PeerTube.git] / client / src / app / core / menu / menu.component.ts
CommitLineData
df98563e
C
1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'
602eb142 3
df98563e
C
4import { AuthService, AuthStatus } from '../auth'
5import { ConfigService } from '../config'
602eb142
C
6
7@Component({
8 selector: 'my-menu',
383bfc83 9 templateUrl: './menu.component.html',
3eeeb87f 10 styleUrls: [ './menu.component.scss' ]
602eb142
C
11})
12export class MenuComponent implements OnInit {
df98563e 13 isLoggedIn: boolean
602eb142
C
14
15 constructor (
16 private authService: AuthService,
a184c71b 17 private configService: ConfigService,
602eb142
C
18 private router: Router
19 ) {}
20
df98563e
C
21 ngOnInit () {
22 this.isLoggedIn = this.authService.isLoggedIn()
602eb142
C
23
24 this.authService.loginChangedSource.subscribe(
25 status => {
26 if (status === AuthStatus.LoggedIn) {
df98563e
C
27 this.isLoggedIn = true
28 console.log('Logged in.')
602eb142 29 } else if (status === AuthStatus.LoggedOut) {
df98563e
C
30 this.isLoggedIn = false
31 console.log('Logged out.')
602eb142 32 } else {
df98563e 33 console.error('Unknown auth status: ' + status)
602eb142
C
34 }
35 }
df98563e 36 )
602eb142
C
37 }
38
291e8d3e
C
39 isRegistrationAllowed () {
40 return this.configService.getConfig().signup.allowed
a184c71b
C
41 }
42
df98563e
C
43 isUserAdmin () {
44 return this.authService.isAdmin()
602eb142
C
45 }
46
df98563e
C
47 logout () {
48 this.authService.logout()
602eb142 49 // Redirect to home page
df98563e 50 this.router.navigate(['/videos/list'])
602eb142
C
51 }
52}