diff options
Diffstat (limited to 'frontend/src/app/_pages/profile')
-rw-r--r-- | frontend/src/app/_pages/profile/profile.component.html | 14 | ||||
-rw-r--r-- | frontend/src/app/_pages/profile/profile.component.ts | 47 |
2 files changed, 45 insertions, 16 deletions
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 = ''; + } + } |