Merge with main changes
commit
5a107b0885
|
@ -1,7 +1,7 @@
|
|||
<div class="sidebar" [class.visible]="isVisible">
|
||||
<div class="sidebar-content">
|
||||
<h4>Bienvenido {{username}}</h4>
|
||||
<button mat-flat-button color="primary" (click)="editUser(username)">Editar usuario</button>
|
||||
<button mat-flat-button color="primary" (click)="editUser('username')">Editar usuario</button>
|
||||
<button mat-flat-button color="accent" routerLink="/admin" *ngIf="isSuperAdmin">Admin</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -12,17 +12,18 @@ import { ChangePasswordModalComponent } from '../../pages/admin/users/users/chan
|
|||
export class SidebarComponent {
|
||||
@Input() isVisible: boolean = false;
|
||||
isSuperAdmin: boolean = false;
|
||||
username: string = localStorage.getItem('username') ?? '';
|
||||
|
||||
username: string = "";
|
||||
decodedToken: any = "";
|
||||
constructor(public dialog: MatDialog) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
const token = localStorage.getItem('loginToken');
|
||||
if (token) {
|
||||
try {
|
||||
const decodedToken: any = jwtDecode(token);
|
||||
console.log('Decoded JWT:', decodedToken);
|
||||
this.isSuperAdmin = decodedToken.roles.includes('ROLE_SUPER_ADMIN');
|
||||
this.decodedToken = jwtDecode(token);
|
||||
console.log('Decoded token:', this.decodedToken);
|
||||
this.isSuperAdmin = this.decodedToken.roles.includes('ROLE_SUPER_ADMIN');
|
||||
this.username = this.decodedToken.username;
|
||||
} catch (error) {
|
||||
console.error('Error decoding JWT:', error);
|
||||
}
|
||||
|
@ -32,10 +33,10 @@ export class SidebarComponent {
|
|||
editUser(user: any) {
|
||||
// Implementar la lógica de edición
|
||||
const dialogRef = this.dialog.open(ChangePasswordModalComponent, {
|
||||
data: { user: user }
|
||||
data: { user: this.decodedToken.username, uuid: this.decodedToken.uuid },
|
||||
});
|
||||
dialogRef.componentInstance.userEdited.subscribe(() => {
|
||||
/* dialogRef.componentInstance.userEdited.subscribe(() => {
|
||||
console.log("User edited successfully!")
|
||||
});
|
||||
}); */
|
||||
}
|
||||
}
|
|
@ -1,10 +1,15 @@
|
|||
.user-form .form-field {
|
||||
display: block;
|
||||
margin-bottom: 10px; /* Puedes ajustar el valor para cambiar la separación */
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.checkbox-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px; /* Ajusta este valor según necesites */
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: red;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
|
@ -6,13 +6,21 @@
|
|||
<input matInput formControlName="username">
|
||||
</mat-form-field>
|
||||
<mat-form-field class="form-field">
|
||||
<mat-label>Contraseña</mat-label>
|
||||
<mat-label>Nueva contraseña</mat-label>
|
||||
<input matInput formControlName="password" type="password">
|
||||
</mat-form-field>
|
||||
<mat-form-field class="form-field">
|
||||
<mat-label>Repite la contraseña</mat-label>
|
||||
<input matInput formControlName="confirmPassword" type="password">
|
||||
</mat-form-field>
|
||||
|
||||
@if (passwordMismatch) {
|
||||
<div class="error-message">Las contraseñas no coinciden</div>
|
||||
}
|
||||
|
||||
@if (updateError) {
|
||||
<div class="error-message">Error, inténtelo de nuevo</div>
|
||||
}
|
||||
</form>
|
||||
</div>
|
||||
<div mat-dialog-actions>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Component, EventEmitter, Inject, OnInit, Output } from '@angular/core';
|
||||
import { Component, EventEmitter, Inject, Output } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { EditUserModalComponent } from '../edit-user-modal/edit-user-modal.component';
|
||||
import { UserService } from '../users.service';
|
||||
|
||||
@Component({
|
||||
|
@ -8,25 +9,28 @@ import { UserService } from '../users.service';
|
|||
templateUrl: './change-password-modal.component.html',
|
||||
styleUrl: './change-password-modal.component.css'
|
||||
})
|
||||
|
||||
export class ChangePasswordModalComponent implements OnInit {
|
||||
export class ChangePasswordModalComponent {
|
||||
@Output() userEdited = new EventEmitter<void>();
|
||||
userForm: FormGroup;
|
||||
passwordMismatch: boolean = false;
|
||||
updateError: boolean = false;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<ChangePasswordModalComponent>,
|
||||
public dialogRef: MatDialogRef<EditUserModalComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private fb: FormBuilder,
|
||||
private userService: UserService
|
||||
) {
|
||||
this.userForm = this.fb.group({
|
||||
username: [this.data.user, Validators.required],
|
||||
password: [''],
|
||||
confirmPassword: ['']
|
||||
password: ['', Validators.required],
|
||||
confirmPassword: ['', Validators.required]
|
||||
}, { validators: this.passwordMatchValidator });
|
||||
}
|
||||
|
||||
ngOnInit(): void {}
|
||||
ngOnInit(): void {
|
||||
console.log('Data:', this.data);
|
||||
}
|
||||
|
||||
onNoClick(): void {
|
||||
this.dialogRef.close();
|
||||
|
@ -34,15 +38,18 @@ export class ChangePasswordModalComponent implements OnInit {
|
|||
|
||||
onSubmit(): void {
|
||||
if (this.userForm.valid) {
|
||||
this.passwordMismatch = false;
|
||||
this.updateError = false;
|
||||
|
||||
const userPayload = {
|
||||
username: this.userForm.value.username,
|
||||
allowedOrganizationalUnits: this.data.user.allowedOrganizationalUnits,
|
||||
allowedOrganizationalUnits: [],
|
||||
password: this.userForm.value.password,
|
||||
enabled: true,
|
||||
userGroups: this.data.user.userGroups
|
||||
userGroups: []
|
||||
};
|
||||
|
||||
this.userService.updateUser(this.data.user.uuid, userPayload).subscribe(
|
||||
console.log("THIS IS THE USER PAYLOAD: ", userPayload);
|
||||
this.userService.updateUser(this.data.uuid, userPayload).subscribe(
|
||||
response => {
|
||||
console.log('User updated successfully:', response);
|
||||
this.userEdited.emit();
|
||||
|
@ -50,12 +57,13 @@ export class ChangePasswordModalComponent implements OnInit {
|
|||
},
|
||||
error => {
|
||||
console.error('Error updating user:', error);
|
||||
// Agregar alguna lógica para manejar el error en la interfaz de usuario
|
||||
this.updateError = true;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
console.error('Form is invalid');
|
||||
// Agregar alguna lógica para manejar el error en la interfaz de usuario
|
||||
this.passwordMismatch = this.userForm.hasError('mismatch');
|
||||
this.updateError = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue