Skip to content

Commit

Permalink
Now you can sign up!
Browse files Browse the repository at this point in the history
  • Loading branch information
Muffinous committed Apr 7, 2020
1 parent af33913 commit 6842a6f
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 51 deletions.
9 changes: 5 additions & 4 deletions frontend/instarecipes/src/app/Interfaces/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ export interface User{
id?: number;
username: string;
email: string;
passwordHash?: string;
roles: string[];
password?: string;
roles?: string[];
authdata?: string;
name: string;
surname: string;
allergen: string;
}
allergens: string;
info: string;
}
2 changes: 1 addition & 1 deletion frontend/instarecipes/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
</div>
</nav>

<router-outlet></router-outlet>
<router-outlet></router-outlet>
5 changes: 4 additions & 1 deletion frontend/instarecipes/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export class AppComponent {
title : "Instarecipes";
currentUser: User;

constructor(private router: Router, public authService: AuthenticationService) { }
constructor(
private router: Router,
public authService: AuthenticationService) { }

logout() {
this.authService.logout().subscribe(
Expand All @@ -22,4 +24,5 @@ export class AppComponent {
(error) => console.log('Error when trying to log out: ' + error),
);
}

}
4 changes: 2 additions & 2 deletions frontend/instarecipes/src/app/profile/profile.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
</script> -->
</head>

<admin-requests></admin-requests>
<!--<admin-requests></admin-requests>-->

<user-info></user-info>

<user-items></user-items>

</html>
</html>
16 changes: 9 additions & 7 deletions frontend/instarecipes/src/app/services/authentication.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Injectable } from '@angular/core';
import { User } from '../Interfaces/user.model';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { map, catchError } from 'rxjs/operators';
import { Observable } from 'rxjs';

@Injectable({ providedIn: 'root' })
export class AuthenticationService {
Expand Down Expand Up @@ -78,15 +79,16 @@ constructor(private http: HttpClient) {

register(user: User ){
console.log("im in authentication.service register ")
console.log(user.username);
console.log(user.email)
console.log(user.passwordHash);
console.log(user.name);
console.log(user.surname);
console.log(user.allergen);
console.log(user);

return this.http.post('/api/signup', user);

}

private handleError(error: any) {
console.error(error);
return Observable.throw("Server error (" + error.status + "): " + error.text())
}


}
1 change: 0 additions & 1 deletion frontend/instarecipes/src/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { User } from '../Interfaces/user.model';
export class UserService {
jsonData;
finalData;
user: User;

constructor(
private http: HttpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
</div>
<div class="form-group">
<div class="wrap-input100">
<label for="passwordHash">Password</label>
<input type="password" formControlName="passwordHash" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.passwordHash.errors }" />
<div *ngIf="submitted && f.passwordHash.errors" class="invalid-feedback">
<div *ngIf="f.passwordHash.errors.required">Password is required</div>
<label for="password">Password</label>
<input type="password" formControlName="password" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.password.errors }" />
<div *ngIf="submitted && f.password.errors" class="invalid-feedback">
<div *ngIf="f.password.errors.required">Password is required</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export class FirstComponent implements OnInit {
this.registerForm = this.formBuilder.group({
username: ['', Validators.required],
email: ['', [Validators.required, Validators.email]],
passwordHash: ['', Validators.required],
password: ['', Validators.required],
confPassword: ['', Validators.required]
}, {
validator: MustMatch('passwordHash', 'confPassword')
validator: MustMatch('password', 'confPassword')
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
</div>
</div>



<div class="flex-col-c">
<p>Complete your profile</p>
<label class="switch">
Expand Down Expand Up @@ -84,7 +82,6 @@
</div>
</div>


</form>
</div>
</div>
30 changes: 24 additions & 6 deletions frontend/instarecipes/src/app/signUp10/second/second.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ProfileService } from 'src/app/services/profile.service';
import { AuthenticationService } from 'src/app/services/authentication.service';
import { ActivatedRoute, Router } from '@angular/router';
import { first } from 'rxjs/operators';
import { User } from 'src/app/Interfaces/user.model';

@Component({
selector: 'app-second',
Expand All @@ -17,14 +18,17 @@ export class SecondComponent implements OnInit {
allergens: Allergen [];
returnUrl: string;
error: '';
user: User;

constructor(
private formBuilder: FormBuilder,
private userService: UserService,
private profileService: ProfileService,
private router: Router,
private authenticationService: AuthenticationService,
) { }
) {
this.user = {username: null, email: '', password: '', name: '', surname: '', info: 'Hello world!', allergens: null};
}

ngOnInit() {
this.getAllergens();
Expand All @@ -34,28 +38,28 @@ export class SecondComponent implements OnInit {
name: ['', Validators.required],
surname: ['', Validators.required],
fileAvatar: [''],
allergen: ['']
allergen: [''],
});
}

onSubmit() {
this.userService.setFinalData(this.registerForm2.value);
console.log("final data " , this.userService.getFinalData());
//this.userService.setUser();
this.setUser();
delete this.userService.getFinalData()['confPassword'];
delete this.userService.getFinalData()['fileAvatar'];

console.log("nuevo ", this.userService.getFinalData());

this.authenticationService.register(this.userService.getFinalData())
this.authenticationService.register(this.user)
.pipe(first())
.subscribe(
data => {
alert("YES!");
alert("User created!");
this.router.navigate(['/login']);
},
error => {
alert("NO!");
alert("Try again");
this.error = error;
});
}
Expand All @@ -77,4 +81,18 @@ export class SecondComponent implements OnInit {
});
}


setUser () {
console.log("Im in setuser()");
this.user["username"] = this.userService.getFinalData()['username'];
this.user['email'] = this.userService.getFinalData()['email'];
this.user['password'] = this.userService.getFinalData()['password'];
this.user['name'] = this.userService.getFinalData()['name'];
this.user['surname'] = this.userService.getFinalData()['surname'];
this.user['allergens'] = this.userService.getFinalData()['allergen'];

console.log("set user ", this.user);

}

}
Empty file.

This file was deleted.

19 changes: 0 additions & 19 deletions frontend/instarecipes/src/app/signUp10/signUp10.component.ts

This file was deleted.

0 comments on commit 6842a6f

Please sign in to comment.