Skip to content
Permalink
Browse files
Improved test data, refactord signup and email
  • Loading branch information
ChrisRollings committed Mar 17, 2019
1 parent ee46fff commit 283e7ed17d03c014f6abf49b2dee66741e10f4e7
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 243 deletions.
@@ -4,7 +4,7 @@ import { IAuthData } from './auth-data';
import { Subject } from 'rxjs';
import { Router } from '@angular/router';
import { LoginComponent } from './login/login.component';
import { environment } from '../../environments/environment'
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root'
})
@@ -26,14 +26,36 @@ export class AuthService {
getUserId() {
return this.userId;
}
createUser(email: string, password: string) {
const authData: IAuthData = { Email: email, Password: password };
this.http.post(this.apiUrl + 'api/user/signup', authData).subscribe(
() => this.router.navigate(['/']),
error => {
this.authStatuesListener.next(false);
}
);

signUp(
boatId: string,
roleId: string,
crewMemberId: string,
userName: string,
password: string,
phoneNumber: string,
dateOfBirth: Date,
email: string,
firstName: string,
lastName: string
): any {
this.http
.post(this.apiUrl + 'api/signup', {
BoatId: boatId,
RoleId: roleId,
CrewMemberId: crewMemberId,
UserName: userName,
Password: password,
PhoneNumber: phoneNumber,
DateOfBirth: dateOfBirth,
Email: email,
FirstName: firstName,
LastName: lastName
})
.subscribe(response => {
console.log('Signup response: ');
console.log(response);
});
}

login(email: string, password) {
@@ -71,7 +93,8 @@ export class AuthService {

autoAuthUser() {
// this.isAuthenticated = true;
//this.authStatuesListener.next(true);
// this.authStatuesListener.next(true);
// return;
const authInformation = this.getAuthData();
if (!authInformation) {
return;
@@ -113,7 +136,7 @@ export class AuthService {
localStorage.setItem('expiration', expirationDate.toISOString());
localStorage.setItem('userId', userId);
}

private clearAuthData() {
localStorage.removeItem('token');
localStorage.removeItem('expiration');
@@ -1,47 +1,21 @@
<div>
<mat-card>
<mat-card-title>Registration Page
</mat-card-title>
<form class="form-container" [formGroup]="form" (submit)="onSubmit()">
<mat-form-field appearance="outline">
<input matInput type="email" formControlName="Email" placeholder="Email">
<mat-error *ngIf="Email.invalid">Please enter a valid email</mat-error>
</mat-form-field>
<mat-card>
<mat-card-title>Login Page
</mat-card-title>
<form class="form-container" [formGroup]="form" (submit)="onSubmit()">
<mat-form-field appearance="outline">
<input matInput type="email" formControlName="Email" placeholder="Email">
<mat-error *ngIf="Email.invalid">Please enter a valid email</mat-error>
</mat-form-field>

<mat-form-field appearance="outline">
<input matInput type="text" formControlName="FirstName" placeholder="First name">
<mat-error *ngIf="FirstName.invalid">Please enter your first name</mat-error>
<mat-form-field appearance="outline">
<input matInput type="password" formControlName="Password" placeholder="Password">
<mat-error *ngIf="Password.invalid">Please enter a password</mat-error>
</mat-form-field>

</mat-form-field>

<mat-form-field appearance="outline">
<input matInput type="text" formControlName="LastName" placeholder="Last name">
<mat-error *ngIf="LastName.invalid">Please enter your last name</mat-error>
</mat-form-field>

<mat-form-field appearance="outline">
<input matInput type="password" formControlName="Password" placeholder="Password">
<mat-error *ngIf="Password.invalid">Please enter a password</mat-error>
</mat-form-field>

<mat-form-field appearance="outline">
<input matInput type="tel" formControlName="PhoneNumber" placeholder="Phone number">
<mat-error *ngIf="PhoneNumber.invalid">Please enter your phone number</mat-error>
</mat-form-field>

<mat-form-field appearance="outline">
<input matInput type="text" formControlName="UserName" placeholder="User name">
<mat-error *ngIf="UserName.invalid">Please enter a username</mat-error>
</mat-form-field>

<mat-form-field appearance="outline">
<input matInput [matDatepicker]="picker" formControlName="DateOfBirth" placeholder="Date of birth">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
<div>
<button type="submit" [disabled]="form.invalid" mat-stroked-button>Login</button>
</div>
</form>
</mat-card>
<div>
<button type="submit" [disabled]="form.invalid" mat-stroked-button>Login</button>
</div>
</form>
</mat-card>
</div>
@@ -18,67 +18,38 @@ export class LoginComponent implements OnInit {
Email: new FormControl(null, {
validators: [Validators.required, Validators.email]
}),
FirstName: new FormControl(null, { validators: [Validators.required] }),
LastName: new FormControl(null, { validators: [Validators.required] }),
DateOfBirth: new FormControl(null, { validators: [Validators.required] }),
PhoneNumber: new FormControl(null, { validators: [Validators.required] }),
UserName: new FormControl(null, { validators: [Validators.required] }),
Password: new FormControl(null, { validators: [Validators.required] })
});
}

// CrewMemberId:string;*
// RoleId:string;*
// BoatId:string;*

// Editable
// DOB:Date;*
// FirstName:string;*
// LastName:string;*
// Email:string;*
// Phone:string;*
// UserName:string;*
// Password:string;*

get BoatId() {
return this.boatId;
}

get RoleId() {
return this.roleId;
}

get CrewMemberId() {
return this.crewMemberId;
}
get UserName() {
return this.form.get('UserName');
}

get Password() {
return this.form.get('Password');
}
get PhoneNumber() {
return this.form.get('UserName');
}
get DateOfBirth() {
return this.form.get('DateOfBirth');
}

get Email() {
return this.form.get('Email');
}
get FirstName() {
return this.form.get('FirstName');
}
get LastName() {
return this.form.get('LastName');
}


onSubmit() {
if (this.form.invalid) {
return;
}

this.authService.login(this.form.value.Email, this.form.value.Password);

}
}



@@ -1,20 +1,19 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { AuthService } from '../auth.service';

@Component({
selector: 'app-signup',
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.scss']
})
export class SignupComponent implements OnInit {

constructor() { }
constructor(private authSerivce: AuthService) {}
form: FormGroup;
private crewMemberId: string;
private roleId: string;
private boatId: string;
ngOnInit() {

this.form = new FormGroup({
Email: new FormControl(null, {
validators: [Validators.required, Validators.email]
@@ -28,33 +27,20 @@ export class SignupComponent implements OnInit {
});
}

// CrewMemberId:string;*
// RoleId:string;*
// BoatId:string;*

// Editable
// DOB:Date;*
// FirstName:string;*
// LastName:string;*
// Email:string;*
// Phone:string;*
// UserName:string;*
// Password:string;*

get BoatId() {
return this.boatId;
}

get RoleId() {
return this.roleId;
}
get CrewMemberId() {
return this.crewMemberId;
}

get UserName() {
return this.form.get('UserName');
}

get Password() {
return this.form.get('Password');
}
@@ -63,22 +49,48 @@ export class SignupComponent implements OnInit {
}
get DateOfBirth() {
return this.form.get('DateOfBirth');
}
}
get Email() {
return this.form.get("Email")
return this.form.get('Email');
}
get FirstName() {
return this.form.get("FirstName")
return this.form.get('FirstName');
}
get LastName() {
return this.form.get("LastName")
return this.form.get('LastName');
}

onSubmit(){
console.log("submit")
console.log(this.form);
if(this.form.invalid){
onSubmit() {
console.log('Signing');
if (this.form.invalid) {
return;
}

this.authSerivce.signUp(
this.boatId,
this.roleId,
this.crewMemberId,
this.UserName.value,
this.Password.value,
this.PhoneNumber.value,
this.DateOfBirth.value,
this.Email.value,
this.FirstName.value,
this.LastName.value
);
}
}

//NOTES:
// CrewMemberId:string;*
// RoleId:string;*
// BoatId:string;*

// Editable
// DOB:Date;*
// FirstName:string;*
// LastName:string;*
// Email:string;*
// Phone:string;*
// UserName:string;*
// Password:string;*
@@ -1,4 +1,4 @@
import { Component, OnInit} from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AuthService } from 'src/app/auth/auth.service';
import { EventService } from '../event.service';
@@ -11,32 +11,28 @@ import { getDate } from 'date-fns';
styleUrls: ['./event.component.scss']
})
export class EventComponent implements OnInit {
EventID: String = '';
EventDetails: String = '';
StartDate: Date = new Date();
EndDate: Date = new Date();
Name: String = 'TODO:WHAT NAME';

EventID:string = "";
EventDetails:string = "";
StartDate:Date = new Date();
EndDate:Date = new Date();
Name:string = "";

constructor(
private router: ActivatedRoute,
private eventService: EventService
) {}

constructor(private router: ActivatedRoute, private eventService:EventService) { }

ngOnInit() {

this.router.paramMap.subscribe(paramMap => {

if (paramMap.has("eventId")) {
if (paramMap.has('eventId')) {
const eventId = paramMap.get('eventId');
this.eventService.getEvent(eventId).subscribe(event => {
//console.log(event.Description)
this.EventID = event.EventId
this.EventDetails = event.Description;
this.StartDate = event.StartDate;
this.EndDate = event.EndDate;
this.Name = event.FirstName + " " + event.LastName;
this.EventID = event.EventId;
this.EventDetails = event.Description;
this.StartDate = event.StartDate;
this.EndDate = event.EndDate;
});
}
})
});
}

}

0 comments on commit 283e7ed

Please sign in to comment.