From 826068cf31ad299ccaf4837707cee59943340b52 Mon Sep 17 00:00:00 2001 From: dotansimha Date: Tue, 27 Sep 2016 13:50:22 +0300 Subject: [PATCH] Step 19.23: Added the signup component --- client/imports/app/auth/signup.component.ts | 43 +++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 client/imports/app/auth/signup.component.ts diff --git a/client/imports/app/auth/signup.component.ts b/client/imports/app/auth/signup.component.ts new file mode 100644 index 000000000..eed82b208 --- /dev/null +++ b/client/imports/app/auth/signup.component.ts @@ -0,0 +1,43 @@ +import {Component, OnInit, NgZone} from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { Router } from '@angular/router'; +import { Accounts } from 'meteor/accounts-base'; + +import template from './signup.component.html'; + +@Component({ + selector: 'signup', + template +}) +export class SignupComponent implements OnInit { + signupForm: FormGroup; + error: string; + + constructor(private router: Router, private zone: NgZone, private formBuilder: FormBuilder) {} + + ngOnInit() { + this.signupForm = this.formBuilder.group({ + email: ['', Validators.required], + password: ['', Validators.required] + }); + + this.error = ''; + } + + signup() { + if (this.signupForm.valid) { + Accounts.createUser({ + email: this.signupForm.value.email, + password: this.signupForm.value.password + }, (err) => { + if (err) { + this.zone.run(() => { + this.error = err; + }); + } else { + this.router.navigate(['/']); + } + }); + } + } +} \ No newline at end of file