Check current password on server side
[oweals/peertube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { BytesPipe } from 'ngx-pipes'
4 import { AuthService } from '../../core'
5 import { User } from '../../shared'
6 import { UserService } from '../../shared/users'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8
9 @Component({
10   selector: 'my-account-settings',
11   templateUrl: './my-account-settings.component.html',
12   styleUrls: [ './my-account-settings.component.scss' ]
13 })
14 export class MyAccountSettingsComponent implements OnInit {
15   user: User = null
16   userVideoQuota = '0'
17   userVideoQuotaUsed = 0
18
19   constructor (
20     private userService: UserService,
21     private authService: AuthService,
22     private notificationsService: NotificationsService,
23     private i18n: I18n
24   ) {}
25
26   get userInformationLoaded () {
27     return this.authService.userInformationLoaded
28   }
29
30   ngOnInit () {
31     this.user = this.authService.getUser()
32
33     this.authService.userInformationLoaded.subscribe(
34       () => {
35         if (this.user.videoQuota !== -1) {
36           this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
37         } else {
38           this.userVideoQuota = this.i18n('Unlimited')
39         }
40       }
41     )
42
43     this.userService.getMyVideoQuotaUsed()
44       .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
45   }
46
47   onAvatarChange (formData: FormData) {
48     this.userService.changeAvatar(formData)
49       .subscribe(
50         data => {
51           this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
52
53           this.user.updateAccountAvatar(data.avatar)
54         },
55
56         err => this.notificationsService.error(this.i18n('Error'), err.message)
57       )
58   }
59 }