Skip to content

Commit

Permalink
feat: user profile password change improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTasev committed Nov 12, 2019
1 parent 312b7a3 commit a13c277
Showing 1 changed file with 43 additions and 47 deletions.
90 changes: 43 additions & 47 deletions apps/gauzy/src/app/pages/auth/profile/profile.component.ts
Expand Up @@ -34,7 +34,7 @@ export class ProfileComponent implements OnInit, OnDestroy {
passwordErrorMsg: string;
repeatPasswordErrorMsg: string;

matchPassword: boolean = true;
matchPassword = true;

constructor(
private fb: FormBuilder,
Expand All @@ -44,6 +44,40 @@ export class ProfileComponent implements OnInit, OnDestroy {
private roleService: RoleService
) {}

private validations = {
passwordControl: () => {
this.password.valueChanges
.pipe(takeUntil(this.ngDestroy$))
.subscribe(() => {
if (this.password.value === this.repeatPassword.value) {
this.matchPassword = true;
} else {
this.matchPassword = false;
}
});
},
repeatPasswordControl: () => {
this.repeatPassword.valueChanges
.pipe(takeUntil(this.ngDestroy$))
.subscribe(() => {
if (this.password.value === this.repeatPassword.value) {
this.matchPassword = true;
} else {
this.matchPassword = false;
}

this.repeatPasswordErrorMsg =
(this.repeatPassword.touched ||
this.repeatPassword.dirty) &&
this.repeatPassword.errors
? this.repeatPassword.errors.validUrl
? this.passwordDoNotMuch()
: Object.keys(this.repeatPassword.errors)[0]
: '';
});
}
};

async ngOnInit() {
try {
const user = await this.userService.getUserById(this.store.userId);
Expand Down Expand Up @@ -73,23 +107,19 @@ export class ProfileComponent implements OnInit, OnDestroy {
}

async submitForm() {
this.accountInfo = {
email: this.form.value['email'],
firstName: this.form.value['firstName'],
imageUrl: this.form.value['imageUrl'],
lastName: this.form.value['lastName']
};

if (this.form.value['password']) {
this.accountInfo = {
email: this.form.value['email'],
firstName: this.form.value['firstName'],
imageUrl: this.form.value['imageUrl'],
lastName: this.form.value['lastName'],
...this.accountInfo,
hash: this.form.value['password']
};
} else {
this.accountInfo = {
email: this.form.value['email'],
firstName: this.form.value['firstName'],
imageUrl: this.form.value['imageUrl'],
lastName: this.form.value['lastName']
};
}
console.log(this.accountInfo);

try {
await this.userService.update(this.store.userId, this.accountInfo);
Expand Down Expand Up @@ -139,40 +169,6 @@ export class ProfileComponent implements OnInit, OnDestroy {
this.validations.repeatPasswordControl();
}

private validations = {
passwordControl: () => {
this.password.valueChanges
.pipe(takeUntil(this.ngDestroy$))
.subscribe((value) => {
if (this.password.value === this.repeatPassword.value) {
this.matchPassword = true;
} else {
this.matchPassword = false;
}
});
},
repeatPasswordControl: () => {
this.repeatPassword.valueChanges
.pipe(takeUntil(this.ngDestroy$))
.subscribe((value) => {
if (this.password.value === this.repeatPassword.value) {
this.matchPassword = true;
} else {
this.matchPassword = false;
}

this.repeatPasswordErrorMsg =
(this.repeatPassword.touched ||
this.repeatPassword.dirty) &&
this.repeatPassword.errors
? this.repeatPassword.errors.validUrl
? this.passwordDoNotMuch()
: Object.keys(this.repeatPassword.errors)[0]
: '';
});
}
};

ngOnDestroy(): void {
this.ngDestroy$.next();
this.ngDestroy$.complete();
Expand Down

0 comments on commit a13c277

Please sign in to comment.