Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { ValidateService } from '../../services/validate.service';
  3. import { ErrorReportService } from '../../services/error-report.service';
  4. import { Router } from '@angular/router';
  5. import { AuthenticateService } from "../../services/authenticate.service";
  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.   username: String;
  14.   password: String;
  15.   fullName: String;
  16.   repeatedPassword: String;
  17.   email: String;
  18.  
  19.   constructor(
  20.     private validateService: ValidateService,
  21.     private errorReportService: ErrorReportService,
  22.     private router: Router,
  23.     private authenticateService: AuthenticateService
  24.   ) { }
  25.  
  26.   ngOnInit() {
  27.   }
  28.  
  29.   onSubmit() {
  30.     const user = {
  31.       username: this.username,
  32.       name: this.fullName,
  33.       email: this.email,
  34.       password: this.password,
  35.       repeatedPassword: this.repeatedPassword
  36.     }
  37.  
  38.     if (!this.validateService.validateRegister(user)) {
  39.       console.log("Popuni sva polja");
  40.       return false;
  41.     }
  42.  
  43.     if (!this.validateService.validateEmail(user.email)) {
  44.       console.log("Use valid email");
  45.       this.errorReportService.invaidEmail(document.getElementsByName("email")[0]);
  46.       return false;
  47.     }
  48.  
  49.     if(!this.validateService.comparePasswords(user.password, user.repeatedPassword)) {
  50.       console.log("Passwords don't match");
  51.       this.errorReportService.invaidPassword(document.getElementsByName("repeatedPassword")[0],document.getElementsByName("password")[0]);
  52.       return false;
  53.     }
  54.  
  55.     //register user
  56.  
  57.     this.authenticateService.registerUser(user).subscribe(data => {
  58.      
  59.       console.log(data);
  60.       if (data.success) {
  61.         console.log('You are now registered and can log in!');
  62.         this.router.navigate(['/login']);
  63.       }
  64.       else {
  65.         console.log('Something when wrong when you registered!');
  66.         this.router.navigate(['/register']);
  67.       }
  68.     });
  69.     // console.log(this.username);
  70.     // console.log(this.password);
  71.     // if(this.password === this.repeatedPassword) console.log('Password match');
  72.     // else console.log("Passwords don't match");
  73.     // console.log(this.email);
  74.   }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement