Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. import {User} from "../models/user.model";
  2. import {Component, OnInit} from "@angular/core";
  3. import {AuthService} from "../services/auth.service";
  4. import {FormBuilder, FormControl, FormGroup, Validator, Validators} from "@angular/forms";
  5. import {Router} from "@angular/router";
  6. import {PasswordValidation} from "../../shared/password-validation";
  7.  
  8. @Component({
  9. selector: 'app-signup',
  10. templateUrl: './singup.component.html'
  11. })
  12.  
  13. export class SignupComponent implements OnInit{
  14. constructor(private authService:AuthService, private router:Router, private fb:FormBuilder){}
  15.  
  16. myForm:FormGroup;
  17.  
  18. ngOnInit(){
  19. this.myForm = this.fb.group({
  20. firstName: ['', Validators.required],
  21. lastName: ['', Validators.required],
  22. email: ['', Validators.compose([Validators.required, Validators.email])],
  23. country: ['', Validators.required],
  24. postalCode: ['', Validators.required],
  25. address: ['', Validators.required],
  26. houseNumber: ['', Validators.required],
  27. password: ['', Validators.required],
  28. confirmPassword: ['', Validators.required]
  29. }, {
  30. validator: PasswordValidation.MatchPassword
  31. })
  32.  
  33. }
  34.  
  35. getEmailError(){
  36. return this.myForm.get('email').hasError('email') ? 'Not a valid e-mail' : '';
  37. }
  38.  
  39. onSubmit(){
  40. const user = new User(
  41. this.myForm.value.email,
  42. this.myForm.value.password,
  43. this.myForm.value.firstName,
  44. this.myForm.value.lastName,
  45. this.myForm.value.country,
  46. this.myForm.value.postalCode,
  47. this.myForm.value.address,
  48. this.myForm.value.houseNumber
  49. );
  50.  
  51. this.authService.signUp(user)
  52. .subscribe(
  53. data =>{
  54. console.log(data);
  55. this.authService.message= "Your acount has been created, you can now log in!";
  56. let redirect = '/auth/signin';
  57. this.router.navigate([redirect]);
  58. },
  59. error => console.error(error)
  60. );
  61.  
  62. this.myForm.reset();
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement