feat: sincronización avanzada SIU por código ASIG, perfil con foto/nombre de Moodle y refinamiento visual violeta
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
import { PerfilPage } from './perfil.page';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: PerfilPage
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class PerfilPageRoutingModule {}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
import { PerfilPageRoutingModule } from './perfil-routing.module';
|
||||
import { PerfilPage } from './perfil.page';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
IonicModule,
|
||||
PerfilPageRoutingModule
|
||||
],
|
||||
declarations: [PerfilPage]
|
||||
})
|
||||
export class PerfilPageModule {}
|
||||
@@ -0,0 +1,127 @@
|
||||
<ion-header [translucent]="true" class="ion-no-border">
|
||||
<ion-toolbar color="secondary">
|
||||
<ion-buttons slot="start">
|
||||
<ion-back-button defaultHref="/home"></ion-back-button>
|
||||
</ion-buttons>
|
||||
<ion-title>Configuración de Perfil</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
<ion-content [fullscreen]="true" color="light">
|
||||
<div class="profile-header-gradient">
|
||||
<div class="user-avatar-container">
|
||||
<div class="avatar-circle">
|
||||
<img *ngIf="authState?.userPhoto" [src]="authState?.userPhoto" class="user-photo-profile" />
|
||||
<ion-icon *ngIf="!authState?.userPhoto" name="person-circle-outline"></ion-icon>
|
||||
</div>
|
||||
<h2 *ngIf="authState?.userName">{{ authState?.userName }}</h2>
|
||||
<h2 *ngIf="!authState?.userName">Gestión de Cuentas</h2>
|
||||
<p>Unificá tus credenciales de SIU y Campus</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-container">
|
||||
<!-- SIU Guaraní Card -->
|
||||
<ion-card class="auth-card" [class.connected]="authState?.siuConnected">
|
||||
<ion-card-header>
|
||||
<div class="card-title-row">
|
||||
<ion-icon name="school" color="primary" class="service-icon"></ion-icon>
|
||||
<ion-card-title>SIU Guaraní</ion-card-title>
|
||||
<ion-badge *ngIf="authState?.siuConnected" color="primary" class="status-badge">Conectado</ion-badge>
|
||||
<ion-badge *ngIf="!authState?.siuConnected" color="medium" class="status-badge">Sin Vincular</ion-badge>
|
||||
</div>
|
||||
<ion-card-subtitle>Historia Académica y Cartelera Personalizada</ion-card-subtitle>
|
||||
</ion-card-header>
|
||||
|
||||
<ion-card-content *ngIf="!authState?.siuConnected">
|
||||
<p class="auth-desc">Conectá con el SIU para traer tu historial y que la app auto-favoritee tus materias en curso.</p>
|
||||
<ion-list lines="inset" class="auth-form">
|
||||
<ion-item>
|
||||
<ion-icon name="person-outline" slot="start" color="medium"></ion-icon>
|
||||
<ion-input type="text" placeholder="DNI (Sin puntos)" [(ngModel)]="siuDni" clearInput></ion-input>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-icon name="lock-closed-outline" slot="start" color="medium"></ion-icon>
|
||||
<ion-input [type]="showSiuPass ? 'text' : 'password'" placeholder="Contraseña de SIU" [(ngModel)]="siuPass"></ion-input>
|
||||
<ion-button slot="end" fill="clear" (click)="showSiuPass = !showSiuPass" color="medium">
|
||||
<ion-icon [name]="showSiuPass ? 'eye-off-outline' : 'eye-outline'"></ion-icon>
|
||||
</ion-button>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
<ion-button expand="block" (click)="loginSiu()" class="ion-margin-top btn-connect">
|
||||
<ion-icon name="log-in-outline" slot="start"></ion-icon>
|
||||
Sincronizar SIU
|
||||
</ion-button>
|
||||
<p class="error-text" *ngIf="authState?.siuError">{{ authState?.siuError }}</p>
|
||||
</ion-card-content>
|
||||
|
||||
<ion-card-content *ngIf="authState?.siuConnected">
|
||||
<div class="connected-info">
|
||||
<ion-icon name="checkmark-circle" color="primary"></ion-icon>
|
||||
<div class="text">
|
||||
<strong>Cuenta Vinculada</strong>
|
||||
<span>DNI: {{ siuDni }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<ion-button expand="block" fill="clear" color="danger" (click)="logoutSiu()" class="btn-logout">
|
||||
<ion-icon name="log-out-outline" slot="start"></ion-icon>
|
||||
Cerrar sesión SIU
|
||||
</ion-button>
|
||||
</ion-card-content>
|
||||
</ion-card>
|
||||
|
||||
<!-- Campus UNICABA (Moodle) Card -->
|
||||
<ion-card class="auth-card" [class.connected]="authState?.moodleConnected">
|
||||
<ion-card-header>
|
||||
<div class="card-title-row">
|
||||
<ion-icon name="book" color="secondary" class="service-icon"></ion-icon>
|
||||
<ion-card-title>Campus UNICABA</ion-card-title>
|
||||
<ion-badge *ngIf="authState?.moodleConnected" color="primary" class="status-badge">Conectado</ion-badge>
|
||||
<ion-badge *ngIf="!authState?.moodleConnected" color="medium" class="status-badge">Sin Vincular</ion-badge>
|
||||
</div>
|
||||
<ion-card-subtitle>Credencial Digital y Aulas Virtuales</ion-card-subtitle>
|
||||
</ion-card-header>
|
||||
|
||||
<ion-card-content *ngIf="!authState?.moodleConnected">
|
||||
<p class="auth-desc">Vinculá tu cuenta del campus para generar tu credencial digital offline y habilitar alertas de actividades.</p>
|
||||
<ion-list lines="inset" class="auth-form">
|
||||
<ion-item>
|
||||
<ion-icon name="person-outline" slot="start" color="medium"></ion-icon>
|
||||
<ion-input type="text" placeholder="DNI de Campus" [(ngModel)]="moodleDni" clearInput></ion-input>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-icon name="lock-closed-outline" slot="start" color="medium"></ion-icon>
|
||||
<ion-input [type]="showMoodlePass ? 'text' : 'password'" placeholder="Contraseña de Campus" [(ngModel)]="moodlePass"></ion-input>
|
||||
<ion-button slot="end" fill="clear" (click)="showMoodlePass = !showMoodlePass" color="medium">
|
||||
<ion-icon [name]="showMoodlePass ? 'eye-off-outline' : 'eye-outline'"></ion-icon>
|
||||
</ion-button>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
<ion-button expand="block" color="secondary" (click)="loginMoodle()" class="ion-margin-top btn-connect">
|
||||
<ion-icon name="card-outline" slot="start"></ion-icon>
|
||||
Vincular Credencial
|
||||
</ion-button>
|
||||
<p class="error-text" *ngIf="authState?.moodleError">{{ authState?.moodleError }}</p>
|
||||
</ion-card-content>
|
||||
|
||||
<ion-card-content *ngIf="authState?.moodleConnected">
|
||||
<div class="connected-info">
|
||||
<ion-icon name="checkmark-circle" color="secondary"></ion-icon>
|
||||
<div class="text">
|
||||
<strong>Cuenta Vinculada</strong>
|
||||
<span>DNI: {{ moodleDni }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<ion-button expand="block" fill="clear" color="danger" (click)="logoutMoodle()" class="btn-logout">
|
||||
<ion-icon name="log-out-outline" slot="start"></ion-icon>
|
||||
Cerrar sesión Campus
|
||||
</ion-button>
|
||||
</ion-card-content>
|
||||
</ion-card>
|
||||
|
||||
<div class="security-info ion-padding">
|
||||
<ion-icon name="shield-checkmark" color="medium"></ion-icon>
|
||||
<p>Tus credenciales se almacenan de forma segura y local en tu dispositivo. No son enviadas a servidores externos ajenos a la universidad.</p>
|
||||
</div>
|
||||
</div>
|
||||
</ion-content>
|
||||
@@ -0,0 +1,194 @@
|
||||
.profile-header-gradient {
|
||||
background: linear-gradient(135deg, var(--ion-color-secondary) 0%, var(--ion-color-primary) 100%);
|
||||
padding: 40px 20px 60px 20px;
|
||||
text-align: center;
|
||||
color: white;
|
||||
border-bottom-left-radius: 40px;
|
||||
border-bottom-right-radius: 40px;
|
||||
box-shadow: 0 10px 30px rgba(var(--ion-color-primary-rgb), 0.3);
|
||||
|
||||
.user-avatar-container {
|
||||
.avatar-circle {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
backdrop-filter: blur(10px);
|
||||
border-radius: 50%;
|
||||
margin: 0 auto 15px auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
overflow: hidden;
|
||||
|
||||
ion-icon {
|
||||
font-size: 50px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.user-photo-profile {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-weight: 700;
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 5px 0 0 0;
|
||||
opacity: 0.9;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.content-container {
|
||||
margin-top: -30px;
|
||||
padding: 0 16px 20px 16px;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
border-radius: 20px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
|
||||
border: 1px solid rgba(0, 0, 0, 0.03);
|
||||
overflow: hidden;
|
||||
transition: all 0.3s ease;
|
||||
|
||||
&.connected {
|
||||
border-left: 6px solid var(--ion-color-primary);
|
||||
}
|
||||
|
||||
ion-card-header {
|
||||
padding-bottom: 5px;
|
||||
|
||||
.card-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 6px;
|
||||
|
||||
.service-icon {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
ion-card-title {
|
||||
font-weight: 700;
|
||||
font-size: 1.2rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
font-size: 0.75rem;
|
||||
padding: 6px 10px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
ion-card-subtitle {
|
||||
font-size: 0.85rem;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
}
|
||||
|
||||
.auth-desc {
|
||||
font-size: 0.9rem;
|
||||
color: var(--ion-color-medium);
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
|
||||
ion-item {
|
||||
--padding-start: 10px;
|
||||
--inner-padding-end: 10px;
|
||||
--border-radius: 12px;
|
||||
background: var(--ion-color-light);
|
||||
margin-bottom: 8px;
|
||||
--border-color: rgba(0, 0, 0, 0.05);
|
||||
|
||||
ion-icon {
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-connect {
|
||||
margin-top: 20px;
|
||||
--border-radius: 12px;
|
||||
font-weight: 600;
|
||||
height: 48px;
|
||||
box-shadow: 0 4px 15px rgba(var(--ion-color-primary-rgb), 0.2);
|
||||
}
|
||||
|
||||
.connected-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
background: rgba(var(--ion-color-primary-rgb), 0.1);
|
||||
padding: 15px;
|
||||
border-radius: 15px;
|
||||
margin-bottom: 10px;
|
||||
|
||||
ion-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
strong {
|
||||
font-size: 1rem;
|
||||
color: var(--ion-color-dark);
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 0.85rem;
|
||||
color: var(--ion-color-medium);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-logout {
|
||||
--color: var(--ion-color-danger);
|
||||
font-weight: 500;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: var(--ion-color-danger);
|
||||
font-size: 0.85rem;
|
||||
margin-top: 10px;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.security-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
gap: 10px;
|
||||
opacity: 0.7;
|
||||
|
||||
ion-icon {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 0.8rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
max-width: 250px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { ToastController, LoadingController, AlertController, NavController } from '@ionic/angular';
|
||||
import { AuthService, AuthState } from '../services/auth.service';
|
||||
import { SiuService } from '../services/siu-guarani.service';
|
||||
import { CredencialService } from '../services/credencial.service';
|
||||
import { LocalStorageService, AppData } from '../services/local-storage.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-perfil',
|
||||
templateUrl: './perfil.page.html',
|
||||
styleUrls: ['./perfil.page.scss'],
|
||||
standalone: false
|
||||
})
|
||||
export class PerfilPage implements OnInit, OnDestroy {
|
||||
authState: AuthState | null = null;
|
||||
private authSub: Subscription | null = null;
|
||||
|
||||
// Form states
|
||||
siuDni: string = '';
|
||||
siuPass: string = '';
|
||||
showSiuPass: boolean = false;
|
||||
|
||||
moodleDni: string = '';
|
||||
moodlePass: string = '';
|
||||
showMoodlePass: boolean = false;
|
||||
|
||||
loading: boolean = false;
|
||||
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private siuService: SiuService,
|
||||
private credencialService: CredencialService,
|
||||
private localStorageService: LocalStorageService,
|
||||
private toastCtrl: ToastController,
|
||||
private loadingCtrl: LoadingController,
|
||||
private alertCtrl: AlertController,
|
||||
private navCtrl: NavController
|
||||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.authSub = this.authService.authState$.subscribe(state => {
|
||||
this.authState = state;
|
||||
// Pre-fill DNI if already connected
|
||||
if (state.siuConnected && !this.siuDni) this.siuDni = state.siuDni || '';
|
||||
if (state.moodleConnected && !this.moodleDni) this.moodleDni = state.moodleDni || '';
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.authSub) this.authSub.unsubscribe();
|
||||
}
|
||||
|
||||
async loginSiu() {
|
||||
if (!this.siuDni || !this.siuPass) {
|
||||
this.showToast('Por favor, ingresá DNI y Contraseña', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const loader = await this.loadingCtrl.create({ message: 'Validando con SIU Guaraní...' });
|
||||
await loader.present();
|
||||
|
||||
try {
|
||||
const materias = await this.siuService.getAcademicHistory(this.siuDni, this.siuPass);
|
||||
await this.authService.saveSiuCredentials(this.siuDni, this.siuPass);
|
||||
|
||||
// Persistir datos en LocalStorage para que Home los vea
|
||||
const currentData = await this.localStorageService.loadData() || this.getDefaultData();
|
||||
currentData.siuMaterias = materias;
|
||||
currentData.siuLastSync = new Date().toISOString();
|
||||
|
||||
// Aplicar auto-favoritos (opcional, pero recomendado para consistencia)
|
||||
// Nota: Aquí se podría llamar a una versión compartida de autoCompletarDesdeSiu
|
||||
// Por ahora guardamos para que Home lo procese al volver
|
||||
await this.localStorageService.saveData(currentData);
|
||||
|
||||
this.showToast('¡SIU Guaraní conectado y sincronizado!', 'success');
|
||||
this.siuPass = '';
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
this.authService.setSiuError(e.message || 'Error de conexión');
|
||||
this.showToast('Error al conectar con SIU: ' + (e.message || 'Credenciales inválidas'), 'danger');
|
||||
} finally {
|
||||
await loader.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
async logoutSiu() {
|
||||
const alert = await this.alertCtrl.create({
|
||||
header: 'Cerrar Sesión en SIU',
|
||||
message: '¿Estás seguro de que deseas desconectar tu cuenta de SIU Guaraní? Se borrarán tus credenciales guardadas.',
|
||||
buttons: [
|
||||
{ text: 'Cancelar', role: 'cancel' },
|
||||
{
|
||||
text: 'Cerrar Sesión',
|
||||
role: 'destructive',
|
||||
handler: () => {
|
||||
this.authService.logoutSiu();
|
||||
this.siuDni = '';
|
||||
this.siuPass = '';
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
await alert.present();
|
||||
}
|
||||
|
||||
async loginMoodle() {
|
||||
if (!this.moodleDni || !this.moodlePass) {
|
||||
this.showToast('Por favor, ingresá DNI y Contraseña (Campus)', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
const loader = await this.loadingCtrl.create({ message: 'Validando con Campus UNICABA...' });
|
||||
await loader.present();
|
||||
|
||||
try {
|
||||
// 1. Validar y generar credencial (descarga PDF)
|
||||
await this.credencialService.generateCredential(this.moodleDni, this.moodlePass);
|
||||
|
||||
// 2. Obtener Perfil (Nombre y Foto)
|
||||
const profile = await this.credencialService.getUserProfile(this.moodleDni, this.moodlePass);
|
||||
await this.authService.saveUserProfile(profile.name, profile.photo);
|
||||
|
||||
// 3. Guardar credenciales de acceso
|
||||
await this.authService.saveMoodleCredentials(this.moodleDni, this.moodlePass);
|
||||
|
||||
this.showToast('¡Perfil sincronizado y Campus conectado!', 'success');
|
||||
this.moodlePass = '';
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
this.authService.setMoodleError(e.message || 'Error de conexión');
|
||||
this.showToast('Error al conectar con Campus: ' + (e.message || 'Credenciales inválidas'), 'danger');
|
||||
} finally {
|
||||
await loader.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
async logoutMoodle() {
|
||||
const alert = await this.alertCtrl.create({
|
||||
header: 'Cerrar Sesión en Campus',
|
||||
message: '¿Estás seguro de que deseas desconectar tu cuenta del Campus? Se borrará tu credencial digital cacheada.',
|
||||
buttons: [
|
||||
{ text: 'Cancelar', role: 'cancel' },
|
||||
{
|
||||
text: 'Cerrar Sesión',
|
||||
role: 'destructive',
|
||||
handler: () => {
|
||||
this.authService.logoutMoodle();
|
||||
this.moodleDni = '';
|
||||
this.moodlePass = '';
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
await alert.present();
|
||||
}
|
||||
|
||||
goBack() {
|
||||
this.navCtrl.back();
|
||||
}
|
||||
|
||||
private async showToast(message: string, color: 'success' | 'warning' | 'danger') {
|
||||
const toast = await this.toastCtrl.create({
|
||||
message,
|
||||
duration: 3000,
|
||||
color,
|
||||
position: 'bottom'
|
||||
});
|
||||
await toast.present();
|
||||
}
|
||||
|
||||
private getDefaultData(): AppData {
|
||||
return {
|
||||
favoritos: [],
|
||||
eventos: [],
|
||||
aprobadas: [],
|
||||
encurso: [],
|
||||
optativas: [],
|
||||
siuMaterias: [],
|
||||
siuLastSync: null
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user