-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementar el login y registro de usuarios en el FrontEnd
- Loading branch information
1 parent
4949c96
commit 97a9dc7
Showing
26 changed files
with
697 additions
and
556 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,97 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Component } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { FormBuilder, Validators, FormGroup } from '@angular/forms'; | ||
import Swal from 'sweetalert2' | ||
|
||
import { UsuarioService } from '../../services/usuario.service'; | ||
|
||
@Component({ | ||
selector: 'app-register', | ||
templateUrl: './register.component.html', | ||
styleUrls: [ './register.component.css' ] | ||
}) | ||
export class RegisterComponent implements OnInit { | ||
export class RegisterComponent { | ||
|
||
public formSubmitted = false; | ||
|
||
public registerForm = this.fb.group({ | ||
nombre: ['Fernando', Validators.required ], | ||
email: ['test100@gmail.com', [ Validators.required, Validators.email ] ], | ||
password: ['123456', Validators.required ], | ||
password2: ['123456', Validators.required ], | ||
terminos: [ true, Validators.required ], | ||
}, { | ||
validators: this.passwordsIguales('password', 'password2') | ||
}); | ||
|
||
constructor( private fb: FormBuilder, | ||
private usuarioService: UsuarioService, | ||
private router: Router ) { } | ||
|
||
crearUsuario() { | ||
this.formSubmitted = true; | ||
console.log( this.registerForm.value ); | ||
|
||
if ( this.registerForm.invalid ) { | ||
return; | ||
} | ||
|
||
// Realizar el posteo | ||
this.usuarioService.crearUsuario( this.registerForm.value ) | ||
.subscribe( resp => { | ||
|
||
// Navegar al Dashboard | ||
this.router.navigateByUrl('/'); | ||
|
||
}, (err) => { | ||
// Si sucede un error | ||
Swal.fire('Error', err.error.msg, 'error' ); | ||
}); | ||
|
||
|
||
} | ||
|
||
campoNoValido( campo: string ): boolean { | ||
|
||
if ( this.registerForm.get(campo).invalid && this.formSubmitted ) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
|
||
} | ||
|
||
contrasenasNoValidas() { | ||
const pass1 = this.registerForm.get('password').value; | ||
const pass2 = this.registerForm.get('password2').value; | ||
|
||
if ( (pass1 !== pass2) && this.formSubmitted ) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
|
||
} | ||
|
||
aceptaTerminos() { | ||
return !this.registerForm.get('terminos').value && this.formSubmitted; | ||
} | ||
|
||
passwordsIguales(pass1Name: string, pass2Name: string ) { | ||
|
||
return ( formGroup: FormGroup ) => { | ||
|
||
const pass1Control = formGroup.get(pass1Name); | ||
const pass2Control = formGroup.get(pass2Name); | ||
|
||
if ( pass1Control.value === pass2Control.value ) { | ||
pass2Control.setErrors(null) | ||
} else { | ||
pass2Control.setErrors({ noEsIgual: true }) | ||
} | ||
|
||
constructor() { } | ||
|
||
ngOnInit(): void { | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.