import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { ErrorComponent } from '../error/error.component'; import {MatDialogRef, MatDialog} from '@angular/material'; import { SadeeService } from '../sadee.servise'; @Component({ selector: 'app-profile', templateUrl: './profile.component.html', styleUrls: ['./profile.component.scss'] }) export class ProfileComponent implements OnInit { router: Router; sadeeService : SadeeService; errDialog : MatDialog; constructor(router: Router, sadeeService : SadeeService, errDialog : MatDialog) { this.router = router; this.sadeeService = sadeeService; this.errDialog = errDialog; } ngOnInit() { } checkIsValidPassword(password) { let hasNumber = /\d/; let hasLetter = /[a-z]/i; if (!(password.match(hasNumber)) || !(password.match(hasLetter))) { return false; } if (password.length <= 5) { return false; } return true; } onSubmit(submittedForm) { if (!this.checkIsValidPassword(submittedForm.value.newPassword)) { let errStr = '.Senha inválida. A nova senha deve ter:\n\t.Uma letra\n\t.Um número\n\t.Mais de 5 caracteres'; let errDialogRef = this.errDialog.open(ErrorComponent, { height: '400px', width: '400px' }); errDialogRef.componentInstance.errorMessage = errStr; } else { this.sadeeService.changePassword(submittedForm.value.oldPassword, submittedForm.value.newPassword); console.log(submittedForm); } } }