diff options
Diffstat (limited to 'frontend/src')
4 files changed, 55 insertions, 21 deletions
diff --git a/frontend/src/app/_modals/register-modal/register-modal.component.ts b/frontend/src/app/_modals/register-modal/register-modal.component.ts index c045f1ce..fe0de92f 100644 --- a/frontend/src/app/_modals/register-modal/register-modal.component.ts +++ b/frontend/src/app/_modals/register-modal/register-modal.component.ts @@ -129,7 +129,8 @@ export class RegisterModalComponent implements OnInit { lastName: this.lastName, username: this.username, password: this.pass1, - email: this.email + email: this.email, + photoId: "1" } this.authService.register(user) diff --git a/frontend/src/app/_pages/profile/profile.component.html b/frontend/src/app/_pages/profile/profile.component.html index bece7c46..fba95218 100644 --- a/frontend/src/app/_pages/profile/profile.component.html +++ b/frontend/src/app/_pages/profile/profile.component.html @@ -7,12 +7,14 @@ <div class="card mb-4 mb-xl-0"> <div class="card-header">Moj profil</div> <div class="card-body text-center"> - <!-- Profile picture image--> - <img class="img-account-profile rounded-circle mb-2" src="http://bootdey.com/img/Content/avatar/avatar1.png" alt=""> - <!-- Profile picture help block--> - <div class="small font-italic text-muted mb-4">JPG or PNG no larger than 5 MB</div> - <!-- Profile picture upload button--> - <button class="btn btn-primary" type="button">Upload new image</button> + <div class=" image d-flex flex-column justify-content-center align-items-center"> + <!-- Profile picture image--> + <img class="img-account-profile rounded-circle mb-2" src="http://bootdey.com/img/Content/avatar/avatar1.png" alt=""> + <!-- User's info --> + <span>@ {{this.user.username}}</span> + <span class="mt-3" style="font-weight: bold;">{{this.user.firstName}} {{this.user.lastName}}</span> + <span>{{this.email}}</span> + </div> </div> </div> </div> diff --git a/frontend/src/app/_pages/profile/profile.component.ts b/frontend/src/app/_pages/profile/profile.component.ts index 4b474678..c155dbff 100644 --- a/frontend/src/app/_pages/profile/profile.component.ts +++ b/frontend/src/app/_pages/profile/profile.component.ts @@ -1,6 +1,9 @@ +import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import User from 'src/app/_data/User'; import { UserInfoService } from 'src/app/_services/user-info.service'; +import { AuthService } from 'src/app/_services/auth.service'; +import { Router } from '@angular/router'; @Component({ selector: 'app-profile', @@ -23,15 +26,13 @@ export class ProfileComponent implements OnInit { wrongPassBool: boolean = false; wrongNewPassBool: boolean = false; - constructor(private userInfoService: UserInfoService) { } + constructor(private userInfoService: UserInfoService, private authService: AuthService, private router: Router) { } ngOnInit(): void { - this.userInfoService.getUsersInfo().subscribe((response) => { + this.userInfoService.getUserInfo().subscribe((response) => { this.user = response; - this.user.password = 'sonja123'; - this.username = this.user.username; this.email = this.user.email; this.firstName = this.user.firstName; @@ -53,6 +54,13 @@ export class ProfileComponent implements OnInit { } this.userInfoService.changeUserInfo(editedUser).subscribe((response: any) =>{ + if (this.user.username != editedUser.username) { //promenio username, ide logout + this.user = editedUser; + alert("Nakon promene korisničkog imena, moraćete ponovo da se ulogujete."); + this.authService.logOut(); + this.router.navigate(['']); + return; + } this.user = editedUser; console.log(this.user); }, (error: any) =>{ @@ -66,8 +74,7 @@ export class ProfileComponent implements OnInit { console.log("zeli da promeni lozinku"); if (this.newPass1 != this.newPass2) { //netacno ponovio novu lozinku this.wrongNewPassBool = true; - this.newPass1 = ''; - this.newPass2 = ''; + this.resetNewPassInputs(); console.log("Netacno ponovljena lozinka"); return; } @@ -75,12 +82,32 @@ export class ProfileComponent implements OnInit { this.wrongPassBool = false; this.wrongNewPassBool = false; - this.userInfoService.changeUserPassword(this.oldPass, this.newPass1).subscribe((response) => { - this.user = response; - console.log(this.user); + let passwordArray: string[] = [this.oldPass, this.newPass1]; + this.userInfoService.changeUserPassword(passwordArray).subscribe((response: any) => { + console.log("PROMENIO LOZINKU"); + this.resetNewPassInputs(); + alert("Nakon promene lozinke, moraćete ponovo da se ulogujete."); + this.authService.logOut(); + this.router.navigate(['']); }, (error: any) => { - + console.log("error poruka: ", error.error); + if (error.error == 'Wrong old password!') { + this.wrongPassBool = true; + (<HTMLSelectElement>document.getElementById("inputPassword")).focus(); + return; + } + else if (error.error == 'Identical password!') { + alert("Stara i nova lozinka su identične."); + this.resetNewPassInputs(); + (<HTMLSelectElement>document.getElementById("inputNewPassword")).focus(); + return; + } }); } + resetNewPassInputs() { + this.newPass1 = ''; + this.newPass2 = ''; + } + } diff --git a/frontend/src/app/_services/user-info.service.ts b/frontend/src/app/_services/user-info.service.ts index b66a73e1..7ed2970c 100644 --- a/frontend/src/app/_services/user-info.service.ts +++ b/frontend/src/app/_services/user-info.service.ts @@ -12,15 +12,19 @@ export class UserInfoService { constructor(private http: HttpClient, private authService: AuthService) { } - getUsersInfo(): Observable<User> { + getUserInfo(): Observable<User> { return this.http.get<User>(`${API_SETTINGS.apiURL}/user/myprofile`, { headers: this.authService.authHeader() }); } changeUserInfo(user: User): any { - return this.http.put(`${API_SETTINGS.apiURL}/user/${user._id}`, user, { headers: this.authService.authHeader() }); + return this.http.put(`${API_SETTINGS.apiURL}/user/changeinfo`, user, { headers: this.authService.authHeader() }); } - changeUserPassword(oldPassword: string, newPassword: string): Observable<User> { - return this.http.put<User>(`${API_SETTINGS.apiURL}/user/`, { oldPassword, newPassword }, { headers: this.authService.authHeader() }); + changeUserPassword(passwordArray: string[]): any { + return this.http.put(`${API_SETTINGS.apiURL}/user/changepass`, passwordArray, { headers: this.authService.authHeader(), responseType: 'text' }); + } + + deleteUser(): any { + return this.http.delete(`${API_SETTINGS.apiURL}/user/deleteprofile`, { headers: this.authService.authHeader() }); } } |