aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_pages/profile/profile.component.ts
diff options
context:
space:
mode:
authorSonja Galovic <galovicsonja@gmail.com>2022-04-02 12:36:03 +0200
committerSonja Galovic <galovicsonja@gmail.com>2022-04-02 12:36:03 +0200
commitc692efb1df7dfba7417d93e80d3cbda6b7f7f182 (patch)
treeaaa8d91d56704583bcbb113438ee70ce64c0eafc /frontend/src/app/_pages/profile/profile.component.ts
parentf694ca566bf29e0129043b6852a613d744ce1c61 (diff)
Profile page - validacija unosa kod izmene profila
Diffstat (limited to 'frontend/src/app/_pages/profile/profile.component.ts')
-rw-r--r--frontend/src/app/_pages/profile/profile.component.ts118
1 files changed, 109 insertions, 9 deletions
diff --git a/frontend/src/app/_pages/profile/profile.component.ts b/frontend/src/app/_pages/profile/profile.component.ts
index 3e9a0d11..7a7796da 100644
--- a/frontend/src/app/_pages/profile/profile.component.ts
+++ b/frontend/src/app/_pages/profile/profile.component.ts
@@ -15,6 +15,8 @@ import shared from '../../Shared';
})
export class ProfileComponent implements OnInit {
+
+
user: User = new User();
pictures: Picture[] = PICTURES;
@@ -71,6 +73,9 @@ export class ProfileComponent implements OnInit {
}
saveInfoChanges() {
+ if (!(this.checkInfoChanges())) //nije prosao regex
+ return;
+
let editedUser: User = {
_id: this.user._id,
username: this.username,
@@ -84,18 +89,20 @@ 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;
+ this.resetInfo();
alert("Nakon promene korisničkog imena, moraćete ponovo da se ulogujete.");
this.authService.logOut();
this.router.navigate(['']);
return;
}
+ alert("Podaci su uspešno promenjeni.");
this.user = editedUser;
console.log(this.user);
this.resetInfo();
}, (error: any) =>{
if (error.error == "Username already exists!") {
alert("Ukucano korisničko ime je već zauzeto!\nIzaberite neko drugo.");
- (<HTMLSelectElement>document.getElementById("inputUsername")).focus();
+ //(<HTMLSelectElement>document.getElementById("inputUsername")).focus();
//poruka obavestenja ispod inputa
this.resetInfo();
}
@@ -103,23 +110,26 @@ export class ProfileComponent implements OnInit {
}
savePasswordChanges() {
+ this.wrongPassBool = false;
+ this.wrongNewPassBool = false;
+
+ if (!(this.checkPasswordChanges())) //nije prosao regex
+ return;
+
if (this.newPass1 == '' && this.newPass2 == '') //ne zeli da promeni lozinku
return;
- console.log("zeli da promeni lozinku");
+ //console.log("zeli da promeni lozinku");
if (this.newPass1 != this.newPass2) { //netacno ponovio novu lozinku
this.wrongNewPassBool = true;
this.resetNewPassInputs();
- console.log("Netacno ponovljena lozinka");
+ //console.log("Netacno ponovljena lozinka");
return;
}
- this.wrongPassBool = false;
- this.wrongNewPassBool = false;
-
let passwordArray: string[] = [this.oldPass, this.newPass1];
this.userInfoService.changeUserPassword(passwordArray).subscribe((response: any) => {
- console.log("PROMENIO LOZINKU");
+ //console.log("PROMENIO LOZINKU");
this.resetNewPassInputs();
alert("Nakon promene lozinke, moraćete ponovo da se ulogujete.");
this.authService.logOut();
@@ -128,13 +138,13 @@ export class ProfileComponent implements OnInit {
console.log("error poruka: ", error.error);
if (error.error == 'Wrong old password!') {
this.wrongPassBool = true;
- (<HTMLSelectElement>document.getElementById("inputPassword")).focus();
+ //(<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();
+ //(<HTMLSelectElement>document.getElementById("inputNewPassword")).focus();
return;
}
});
@@ -161,5 +171,95 @@ export class ProfileComponent implements OnInit {
shared.photoId = this.photoId;
}
+ checkPasswordChanges() : boolean {
+ this.passwordValidation();
+
+ if (!(this.wrongOldPassBool || this.wrongNewPass1Bool || this.wrongNewPass2Bool))
+ return true;
+ return false;
+ }
+ checkInfoChanges() : boolean {
+ this.firstName = this.firstName.trim();
+ this.lastName = this.lastName.trim();
+ this.username = this.username.trim();
+ this.email = this.email.trim();
+
+ this.firstNameValidation();
+ this.lastNameValidation();
+ this.usernameValidation();
+ this.emailValidation();
+
+ if (!(this.wrongUsernameBool || this.wrongEmailBool || this.wrongFirstNameBool || this.wrongLastNameBool))
+ return true;
+ return false;
+ }
+
+ isCorrectName(element: string): boolean {
+ if (this.pattName.test(element) && !(this.pattTwoSpaces.test(element)) && (element.length >= 1 && element.length <= 30))
+ return true;
+ return false;
+ }
+ isCorrectUsername(element: string): boolean {
+ if (this.pattUsername.test(element) && !(this.pattTwoSpaces.test(element)) && (element.length >= 1 && element.length <= 30))
+ return true;
+ return false;
+ }
+ isCorrectEmail(element: string): boolean {
+ if (this.pattEmail.test(element.toLowerCase()) && element.length <= 320)
+ return true;
+ return false;
+ }
+ isCorrectPassword(element: string): boolean {
+ if (this.pattPassword.test(element))
+ return true;
+ return false;
+ }
+ firstNameValidation() {
+ if (this.isCorrectName(this.firstName) == true) {
+ this.wrongFirstNameBool = false;
+ return;
+ }
+ //(<HTMLSelectElement>document.getElementById('firstName')).focus();
+ this.wrongFirstNameBool = true;
+ }
+ lastNameValidation() {
+ if (this.isCorrectName(this.lastName) == true) {
+ this.wrongLastNameBool = false;
+ return;
+ }
+ //(<HTMLSelectElement>document.getElementById('lastName')).focus();
+ this.wrongLastNameBool = true;
+ }
+ usernameValidation() {
+ if (this.isCorrectUsername(this.username) == true) {
+ this.wrongUsernameBool = false;
+ return;
+ }
+ //(<HTMLSelectElement>document.getElementById('username-register')).focus();
+ this.wrongUsernameBool = true;
+ }
+ emailValidation() {
+ if (this.isCorrectEmail(this.email) == true) {
+ this.wrongEmailBool = false;
+ return;
+ }
+ //(<HTMLSelectElement>document.getElementById('email')).focus();
+ this.wrongEmailBool = true;
+ }
+ passwordValidation() {
+ if (this.isCorrectPassword(this.oldPass) && this.isCorrectPassword(this.newPass1) && this.newPass1 == this.newPass2) {
+ this.wrongOldPassBool = false;
+ this.wrongNewPass1Bool = false;
+ this.wrongNewPass2Bool = false;
+ return;
+ }
+ this.oldPass = '';
+ this.newPass1 = '';
+ this.newPass2 = '';
+ //(<HTMLSelectElement>document.getElementById('pass1')).focus();
+ this.wrongOldPassBool = true;
+ this.wrongNewPass1Bool = true;
+ this.wrongNewPass2Bool = true;
+ }
}