Fix mod ui build issues
[dcaegen2/platform.git] / mod2 / ui / src / app / reset-password / reset-password.component.ts
1 /* 
2  *  # ============LICENSE_START=======================================================
3  *  # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
4  *  # ================================================================================
5  *  # Licensed under the Apache License, Version 2.0 (the "License");
6  *  # you may not use this file except in compliance with the License.
7  *  # You may obtain a copy of the License at
8  *  #
9  *  #      http://www.apache.org/licenses/LICENSE-2.0
10  *  #
11  *  # Unless required by applicable law or agreed to in writing, software
12  *  # distributed under the License is distributed on an "AS IS" BASIS,
13  *  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  # See the License for the specific language governing permissions and
15  *  # limitations under the License.
16  *  # ============LICENSE_END=========================================================
17  */
18
19 import { Component, OnInit } from '@angular/core';
20 import { FormGroup, FormBuilder, Validators } from '@angular/forms';
21 import { AuthService } from '../services/auth.service';
22 import { Router } from '@angular/router';
23 import { User } from '../models/User';
24
25 @Component({
26   selector: 'app-reset-password',
27   templateUrl: './reset-password.component.html',
28   styleUrls: ['./reset-password.component.css']
29 })
30 export class ResetPasswordComponent implements OnInit {
31
32   form: FormGroup;
33
34   constructor(private fb: FormBuilder, public authService: AuthService, private router: Router) { }
35
36   ngOnInit() {
37     this.form = this.fb.group({
38         id: ['', [Validators.required]],
39         password: '',
40         newPassword: '',
41         confirm_newPassword: ''
42     });
43   }
44
45   cancel() {
46     this.form.reset();
47   }
48
49   generateNewPassword() {
50     this.form.value.password = '';
51     let p = '';
52     const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&';
53     for(let i=1;i<12;i++) {
54       const index = Math.floor(Math.random() * chars.length + 1);
55       this.form.value.password += chars.charAt(index);
56     }
57     this.form.patchValue({password: this.form.value.password});
58   }
59
60   submit() {
61     const id = this.form.value.id;
62     if(!this.authService.isAdmin){
63     if(this.form.value.newPassword === this.form.value.confirm_newPassword){
64       const password = this.form.value.newPassword;
65       console.log(id);
66       console.log(password); // toJane: need to call user API
67     } else {
68       alert('Your passwords do not match, please re-confirm!');
69       this.form.patchValue({newPassword: '', confirm_newPassword: ''});
70     }
71   } else {
72      const password = this.form.value.password;
73      console.log(id);
74      console.log(password);// toJane: need to call user API
75   }
76 }
77
78 }