Guest User

Untitled

a guest
Jul 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { ValidateService } from '../../services/validate.service';
  3. import { FlashMessagesService } from 'angular2-flash-messages';
  4. import { AuthService } from '../../services/auth.service';
  5. import { Router } from '@angular/router';
  6.  
  7. @Component({
  8. selector: 'app-register',
  9. templateUrl: './register.component.html',
  10. styleUrls: ['./register.component.css']
  11. })
  12. export class RegisterComponent implements OnInit {
  13. name: String;
  14. username: String;
  15. email: String;
  16. password: String;
  17.  
  18. constructor(private validateService: ValidateService, private flashMessages: FlashMessagesService, private authService: AuthService, private router: Router) { }
  19.  
  20. ngOnInit() { }
  21.  
  22.  
  23. onRegisterSubmit() {
  24. const user = {
  25. name: this.name,
  26. email: this.email,
  27. username: this.username,
  28. password: this.password
  29. }
  30.  
  31. if (!this.validateService.validateRegister(user)) {
  32. this.flashMessages.show('Please fill in all fields', { cssClass: 'alert-danger', timeout: '3500' });
  33. return false;
  34. }
  35.  
  36. if (!this.validateService.validateEmail(user.email)) {
  37. this.flashMessages.show('Please use a valid email', { cssClass: 'alert-danger', timeout: '3500' });
  38. return false;
  39. }
  40.  
  41. this.authService.registerUser(user).subscribe(data => {
  42. if (data.done) {
  43. this.flashMessages.show('You are now registered and can login', { cssClass: 'alert-success', timeout: 3000 });
  44. this.router.navigate(['/login']);
  45. } else {
  46.  
  47. this.flashMessages.show('something went wrong', { cssClass: 'alert-danger', timeout: 3000 });
  48. this.router.navigate(['/register']);
  49. }
  50.  
  51. });
  52. }
  53. }
Add Comment
Please, Sign In to add comment