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
9 * # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
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';
26 selector: 'app-reset-password',
27 templateUrl: './reset-password.component.html',
28 styleUrls: ['./reset-password.component.css']
30 export class ResetPasswordComponent implements OnInit {
34 constructor(private fb: FormBuilder, public authService: AuthService, private router: Router) { }
37 this.form = this.fb.group({
38 id: ['', [Validators.required]],
41 confirm_newPassword: ''
49 generateNewPassword() {
50 this.form.value.password = '';
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);
57 this.form.patchValue({password: this.form.value.password});
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;
66 console.log(password); // toJane: need to call user API
68 alert('Your passwords do not match, please re-confirm!');
69 this.form.patchValue({newPassword: '', confirm_newPassword: ''});
72 const password = this.form.value.password;
74 console.log(password);// toJane: need to call user API