aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/app/+my-account/my-account-settings/my-account-danger-zone/my-account-danger-zone.component.ts
blob: 4a46f1ad9072558f6e3aade03f6d39809aca50d1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
                                                
                                                                                                     










                                                          
                               

                                           
                                            
       


                                                           
                                         

                                                                                                                                                                                                                                 
                         

                                     


                             



                                                                    
 


                                                   
 

                                                      

   
import { Component, Input } from '@angular/core'
import { AuthService, ConfirmService, Notifier, RedirectService, User, UserService } from '@app/core'

@Component({
  selector: 'my-account-danger-zone',
  templateUrl: './my-account-danger-zone.component.html',
  styleUrls: [ './my-account-danger-zone.component.scss' ]
})
export class MyAccountDangerZoneComponent {
  @Input() user: User = null

  constructor (
    private authService: AuthService,
    private notifier: Notifier,
    private userService: UserService,
    private confirmService: ConfirmService,
    private redirectService: RedirectService
  ) { }

  async deleteMe () {
    const res = await this.confirmService.confirmWithInput(
      // eslint-disable-next-line max-len
      $localize`Are you sure you want to delete your account? This will delete all your data, including channels, videos and comments. Content cached by other servers and other third-parties might make longer to be deleted.`,
      $localize`Type your username to confirm`,
      this.user.username,
      $localize`Delete your account`,
      $localize`Delete my account`
    )
    if (res === false) return

    this.userService.deleteMe()
      .subscribe({
        next: () => {
          this.notifier.success($localize`Your account is deleted.`)

          this.authService.logout()
          this.redirectService.redirectToHomepage()
        },

        error: err => this.notifier.error(err.message)
      })
  }
}