Advertisement
Guest User

Untitled

a guest
Jun 26th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
  2. import { TranslateService } from '@ngx-translate/core';
  3. import { HttpClient } from '@angular/common/http';
  4. import { Router, ActivatedRoute, ParamMap } from '@angular/router';
  5. import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
  6. import { CustomValidators } from "ng2-validation/dist";
  7. import { Observable, Subscription } from 'rxjs/Rx';
  8.  
  9. @Component({
  10.         selector: 'app-reset-password',
  11.         templateUrl: './reset-password.component.html',
  12.         styleUrls: ['./reset-password.component.scss'],
  13.         encapsulation: ViewEncapsulation.None
  14. })
  15. export class ResetPasswordComponent implements OnInit, OnDestroy  {
  16.         public form: FormGroup;
  17.         private userId: string;
  18.         private code: string;
  19.         public busy: boolean = false;
  20.         public success: boolean = false;
  21.         private actionResult = undefined;
  22.         private timer;
  23.         // Subscription object
  24.         private sub: Subscription;
  25.  
  26.         constructor(private fb: FormBuilder, private route: ActivatedRoute, private router: Router,
  27.                 private http: HttpClient, public translate: TranslateService) {
  28.                 this.route.queryParams.subscribe(params => {
  29.                         if (params['userId']) {
  30.                                 this.userId = params['userId'];
  31.                         }
  32.                         if (params['code']) {
  33.                                 this.code = params['code'];
  34.                         }
  35.                 });
  36.         }
  37.  
  38.         ngOnInit() {
  39.                 this.form = this.fb.group({
  40.                         email: [null, Validators.compose([Validators.required, CustomValidators.email])],
  41.                         password: [null, Validators.compose([Validators.required])],
  42.                         passwordConfirm: [null, Validators.compose([Validators.required])]
  43.                 });
  44.                 this.timer = Observable.timer(3000, 0);
  45.         }
  46.  
  47.         onSubmit() {
  48.                 this.busy = true;
  49.                 this.http.post<any[]>('api/zebratixaccount/resetpassword', {
  50.                         'email': this.form.value.email, 'password': this.form.value.password, 'confirmPassword': this.form.value.passwordConfirm, 'code': this.code}).subscribe(res => {
  51.                         this.success = true;
  52.                         this.busy = false;
  53.                         this.translate.get("EmailConfirmSuccessfullyCompleted").subscribe(value => this.actionResult = value);
  54.                         this.sub = this.timer.subscribe(t => { this.router.navigate(['/']); });
  55.  
  56.                 },
  57.                         error => {
  58.                                 this.busy = false;
  59.                                 this.actionResult = error.error.errorMsg;
  60.                         });            
  61.         }
  62.  
  63.         ngOnDestroy() {
  64.                 console.log("Destroy timer");
  65.                 // unsubscribe here
  66.                 this.sub.unsubscribe();
  67.         }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement