Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.63 KB | None | 0 0
  1. import { Component, OnInit, NgZone } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
  4. import { CustomValidators } from 'ng2-validation';
  5.  
  6. import { UserManagementService } from './user-management.service';
  7. import { TeamService } from './team.service';
  8.  
  9. const password = new FormControl('', Validators.required);
  10.  
  11. @Component({
  12. selector: 'app-signup',
  13. templateUrl: './signup.component.html',
  14. styleUrls: ['./signup.component.scss']
  15. })
  16. export class SignupComponent implements OnInit {
  17.  
  18. model: any = {};
  19. public form: FormGroup;
  20. public form2: FormGroup;
  21. teamView: boolean = false;
  22. sUser: object = {};
  23. accountSubmitted = false;
  24. teamSubmitted = false;
  25. accountError: string;
  26. teamError: string;
  27. constructor(private fb: FormBuilder, private router: Router, private zone: NgZone, private userService: UserManagementService, private teamService: TeamService) {
  28. console.log('Signup constructor');
  29. }
  30.  
  31. ngOnInit() {
  32. console.log('Signup init');
  33. this.form = this.fb.group( {
  34. name: [null , Validators.compose ( [ Validators.required ] )],
  35. email: [null, Validators.compose([Validators.required, CustomValidators.email])],
  36. password: password
  37. } );
  38. var pattern = '/^S+$/';
  39. this.form2 = this.fb.group ( {
  40. teamname: [null, Validators.compose([Validators.required, Validators.minLength(3)])]
  41. });
  42. console.info(this.userService.getUser());
  43. }
  44.  
  45. onSubmit() {
  46. var s = this.userService.signUp(this.form.value.name, this.form.value.email, this.form.value.password)
  47. .subscribe((res) => {
  48. this.zone.run(() => {
  49. this.sUser = res;
  50. this.teamView = true;
  51. });
  52. }, (error) => {
  53. console.error(error);
  54. this.accountError = error.message;
  55. this.accountSubmitted = false;
  56. });
  57. this.accountSubmitted = true;
  58. }
  59.  
  60. createTeam() {
  61. this.teamService.createTeam(this.form2.value.teamname)
  62. .subscribe(
  63. result => {
  64. console.info("first subscription:::");
  65. console.info(result);
  66. this.teamService.addTeamToUser(result, this.sUser)
  67. .subscribe(
  68. result => setTimeout(() => this.router.navigate(['/dashboard'])),
  69. error => console.error(error)
  70. )
  71. },
  72. error => {
  73. console.error(error);
  74. this.teamError = error.message;
  75. this.teamSubmitted = false;
  76. }
  77. )
  78. this.teamSubmitted = true;
  79. }
  80. }
  81.  
  82. <div class="session white-bg">
  83. <div class="pattern-left" style="background-image: url('../../assets/images/pattern-left.png')"></div>
  84. <div class="pattern-right" style="background-image: url('../../assets/images/pattern-right.png')"></div>
  85. <div class="session-content">
  86. <div class="session-wrapper">
  87. <md-card>
  88. <md-card-content>
  89. <form [formGroup]="form" (ngSubmit)="onSubmit()" *ngIf="!teamView">
  90. <div class="text-xs-center pb-1">
  91. <img src="assets/images/logo-dark.png" alt=""/>
  92. <p><b>Superpowers await.</b></p>
  93. <p class="mat-text-muted">Create your new account.</p>
  94. </div>
  95. <div fxLayout="column" fxLayoutAlign="space-around">
  96. <div class="pb-1">
  97. <md-input-container style="width: 100%">
  98. <input mdInput placeholder="Name" type="text" [formControl]="form.controls['name']">
  99. </md-input-container>
  100. <small *ngIf="form.controls['name'].hasError('required') && form.controls['name'].touched" class="mat-text-warn">You must include your name.</small>
  101. <small *ngIf="form.controls['name'].errors?.email && form.controls['name'].touched" class="mat-text-warn">You must include a valid name.</small>
  102. </div>
  103. <div class="pb-1">
  104. <md-input-container style="width: 100%">
  105. <input mdInput placeholder="Email address" type="email" [formControl]="form.controls['email']">
  106. </md-input-container>
  107. <small *ngIf="errorMessage" class="mat-text-warn">{{errorMessage}}</small>
  108. <small *ngIf="form.controls['email'].hasError('required') && form.controls['email'].touched" class="mat-text-warn">You must include an email address.</small>
  109. <small *ngIf="form.controls['email'].errors?.email && form.controls['email'].touched" class="mat-text-warn">You must include a valid email address.</small>
  110. </div>
  111. <div class="pb-1">
  112. <md-input-container style="width: 100%">
  113. <input mdInput type="password" placeholder="Password" [formControl]="form.controls['password']">
  114. </md-input-container>
  115. <small *ngIf="form.controls['password'].hasError('required') && form.controls['password'].touched" class="mat-text-warn">You must include password.</small>
  116. </div>
  117. <div class="pb-1">
  118. <md-checkbox>I have read and agree to the terms of service.</md-checkbox>
  119. </div>
  120. <button md-raised-button color="primary" class="btn-block" type="submit" [disabled]="!form.valid || accountSubmitted">
  121. Create your account
  122. <span class="spinner" *ngIf="accountSubmitted">
  123. <svg width='20px' height='20px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-ring">
  124. <rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
  125. <circle cx="50" cy="50" r="40" stroke-dasharray="163.36281798666926 87.9645943005142" stroke="#2c3e50" fill="none" stroke-width="20">
  126. <animateTransform attributeName="transform" type="rotate" values="0 50 50;180 50 50;360 50 50;" keyTimes="0;0.5;1" dur="1s" repeatCount="indefinite" begin="0s"></animateTransform>
  127. </circle>
  128. </svg>
  129. </span>
  130. </button>
  131. <div class="login-error" *ngIf="accountError">
  132. {{accountError}}
  133. </div>
  134. </div>
  135. <div class="pt-1 pb-1 text-xs-center">
  136. <a [routerLink]="['/login']">Already have account? Sign in </a>
  137. &nbsp;&nbsp;&nbsp;&nbsp;
  138. <!--<a>Forgot password?</a>-->
  139. </div>
  140. </form>
  141. <form [formGroup]="form" (ngSubmit)="createTeam()" *ngIf="teamView">
  142. <div class="text-xs-center pb-1">
  143. <img src="assets/images/logo-dark.png" alt=""/>
  144. <p>
  145. <b>Time to name your team.</b>
  146. </p>
  147. <p class="mat-text-muted">Your team name has to be lowercase & contain no spaces.</p>
  148. </div>
  149. <div fxLayout="column" fxLayoutAlign="space-around">
  150. <div class="pb-1">
  151. <md-input-container style="width: 100%">
  152. <input mdInput placeholder="teamname" type="text" [formControl]="form2.controls['teamname']">
  153. </md-input-container>
  154. <small *ngIf="errorMessage" class="mat-text-warn">{{errorMessage}}</small>
  155. <small *ngIf="form2.controls['teamname'].hasError('required') && form2.controls['teamname'].touched" class="mat-text-warn">You must include your teamname.</small>
  156. <small *ngIf="form2.controls['teamname'].hasError('pattern') && form2.controls['teamname'].touched" class="mat-text-warn">You must include a valid teamname (no spaces).</small>
  157. </div>
  158. <button md-raised-button color="primary" class="btn-block" type="submit" [disabled]="!form2.valid || teamSubmitted">
  159. Create your team
  160. <span class="spinner" *ngIf="teamSubmitted">
  161. <svg width='20px' height='20px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-ring">
  162. <rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
  163. <circle cx="50" cy="50" r="40" stroke-dasharray="163.36281798666926 87.9645943005142" stroke="#2c3e50" fill="none" stroke-width="20">
  164. <animateTransform attributeName="transform" type="rotate" values="0 50 50;180 50 50;360 50 50;" keyTimes="0;0.5;1" dur="1s" repeatCount="indefinite" begin="0s"></animateTransform>
  165. </circle>
  166. </svg>
  167. </span>
  168. </button>
  169. <div class="login-error" *ngIf="teamError">
  170. {{teamError}}
  171. </div>
  172. </div>
  173. </form>
  174. </md-card-content>
  175. </md-card>
  176. </div>
  177. </div>
  178. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement