diff options
author | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-24 06:31:08 +0100 |
---|---|---|
committer | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-24 06:31:08 +0100 |
commit | 042482a1bbd6ea3460acf3d71bfe3ef64b05524a (patch) | |
tree | e79413f97a8c9f97c978b5048ab89278ab0e6a41 /frontend/src/app/_pages/profile/profile.component.ts | |
parent | 0aa45260963dbf0a52726f791c3813928a1bcebc (diff) | |
parent | 1113f094ffee030fd9892deb7577927419860013 (diff) |
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into dev
# Conflicts:
# frontend/src/app/app.module.ts
Diffstat (limited to 'frontend/src/app/_pages/profile/profile.component.ts')
-rw-r--r-- | frontend/src/app/_pages/profile/profile.component.ts | 103 |
1 files changed, 91 insertions, 12 deletions
diff --git a/frontend/src/app/_pages/profile/profile.component.ts b/frontend/src/app/_pages/profile/profile.component.ts index 4b474678..3e9a0d11 100644 --- a/frontend/src/app/_pages/profile/profile.component.ts +++ b/frontend/src/app/_pages/profile/profile.component.ts @@ -1,6 +1,12 @@ 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'; +import { PICTURES } from 'src/app/_data/ProfilePictures'; +import { Picture } from 'src/app/_data/ProfilePictures'; +import shared from '../../Shared'; + @Component({ selector: 'app-profile', @@ -10,6 +16,7 @@ import { UserInfoService } from 'src/app/_services/user-info.service'; export class ProfileComponent implements OnInit { user: User = new User(); + pictures: Picture[] = PICTURES; username: string = ''; email: string = ''; @@ -19,24 +26,46 @@ export class ProfileComponent implements OnInit { newPass1: string = ''; newPass2: string = ''; photoId: string = ''; + photoPath: string = ''; wrongPassBool: boolean = false; wrongNewPassBool: boolean = false; - constructor(private userInfoService: UserInfoService) { } + wrongFirstNameBool: boolean = false; + wrongLastNameBool: boolean = false; + wrongUsernameBool: boolean = false; + wrongEmailBool: boolean = false; + wrongOldPassBool: boolean = false; + wrongNewPass1Bool: boolean = false; + wrongNewPass2Bool: boolean = false; + + pattName: RegExp = /^[a-zA-ZšŠđĐčČćĆžŽ]+([ \-][a-zA-ZšŠđĐčČćĆžŽ]+)*$/; + pattUsername: RegExp = /^[a-zA-Z0-9]{6,18}$/; + pattTwoSpaces: RegExp = / /; + pattEmail: RegExp = /^[a-zA-Z0-9]+([\.\-\+][a-zA-Z0-9]+)*\@([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}$/; + pattPassword: RegExp = /.{6,30}$/; + + + 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'; + shared.photoId = this.user.photoId; this.username = this.user.username; this.email = this.user.email; this.firstName = this.user.firstName; this.lastName = this.user.lastName; this.photoId = this.user.photoId; + + for (let i = 0; i < this.pictures.length; i++) { + if (this.pictures[i].photoId.toString() === this.photoId) { + this.photoPath = this.pictures[i].path; + break; + } + } console.log(this.user); }); } @@ -49,14 +78,27 @@ export class ProfileComponent implements OnInit { password: this.user.password, firstName: this.firstName, lastName: this.lastName, - photoId: "1" + photoId: this.photoId } 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); + this.resetInfo(); }, (error: any) =>{ - console.log(error); + if (error.error == "Username already exists!") { + alert("Ukucano korisničko ime je već zauzeto!\nIzaberite neko drugo."); + (<HTMLSelectElement>document.getElementById("inputUsername")).focus(); + //poruka obavestenja ispod inputa + this.resetInfo(); + } }); } @@ -64,10 +106,10 @@ export class ProfileComponent implements OnInit { if (this.newPass1 == '' && this.newPass2 == '') //ne zeli da promeni lozinku return; 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 +117,49 @@ 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 = ''; + } + + resetInfo() { + this.username = this.user.username; + this.email = this.user.email; + this.firstName = this.user.firstName; + this.lastName = this.user.lastName; + this.photoId = this.user.photoId; + + for (let i = 0; i < this.pictures.length; i++) { + if (this.pictures[i].photoId.toString() === this.photoId) { + this.photoPath = this.pictures[i].path; + break; + } + } + shared.photoId = this.photoId; + } + + } |