Changes to local system and enviroment distinction,
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { NgForm } from '@angular/forms';
|
||||
import { NavController } from '@ionic/angular';
|
||||
import { NavController, LoadingController } from '@ionic/angular';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
@Component({
|
||||
selector: 'app-loggin',
|
||||
@@ -11,7 +13,8 @@ export class LogginPage implements OnInit {
|
||||
@ViewChild(NgForm, {static: true}) ngForm: NgForm;
|
||||
errorMessage = null;
|
||||
data = {username: null, password: null,carrer:null};
|
||||
constructor(
|
||||
constructor(private auth: AuthService,
|
||||
private loading: LoadingController,
|
||||
private nav: NavController) { }
|
||||
|
||||
ngOnInit() {
|
||||
@@ -41,7 +44,44 @@ export class LogginPage implements OnInit {
|
||||
this.errorMessage = 'Complete el formulario';
|
||||
return;
|
||||
}
|
||||
console.log(`Data:${this.data.carrer}`)
|
||||
this.nav.navigateRoot('/tabs')
|
||||
this.startLoading()
|
||||
.then(_ => this.auth.signup(this.data).toPromise())
|
||||
.then(success => this.handleSuccess(success), error => this.handleError(error))
|
||||
.finally(() => this.stopoading());
|
||||
console.log(`Data:${this.data.carrer}`);
|
||||
}
|
||||
async startLoading(): Promise<void> {
|
||||
const loading = await this.loading.create({
|
||||
message: '',
|
||||
translucent: true,
|
||||
cssClass: 'custom-loading'
|
||||
});
|
||||
return await loading.present();
|
||||
}
|
||||
|
||||
async stopoading(): Promise<void> {
|
||||
this.loading.dismiss();
|
||||
}
|
||||
|
||||
handleSuccess(response) {
|
||||
this.errorMessage = null;
|
||||
this.nav.navigateRoot('/tabs');
|
||||
}
|
||||
|
||||
handleError(errorResponse: HttpErrorResponse) {
|
||||
console.error(errorResponse.error);
|
||||
|
||||
switch (errorResponse.error.message) {
|
||||
case 'Bad credentials':
|
||||
this.errorMessage = 'El usuario o la contraseña son inválidos';
|
||||
break;
|
||||
default:
|
||||
this.errorMessage = 'Intentelo de nuevo más tarde.';
|
||||
if (errorResponse.error.message) {
|
||||
this.errorMessage = this.errorMessage + ` [${errorResponse.error.message}]`;
|
||||
} else {
|
||||
this.errorMessage = this.errorMessage + ` [${errorResponse.message}]`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,6 @@ export class AuthService {
|
||||
.post<any>(api('/user/sign-up'), signupPayoad)
|
||||
.pipe(tap(this.setSession.bind(this)));
|
||||
}
|
||||
|
||||
getUserAlias(email: String): Observable<any>{
|
||||
return this.http.
|
||||
post<any>(api('/user/alias-giver'),email);
|
||||
}
|
||||
/**
|
||||
* Sets a user session with the given server auth response.
|
||||
* @param authResponse The Server response for authentication.
|
||||
@@ -64,8 +59,6 @@ export class AuthService {
|
||||
if (!authResponse.token || !authResponse.prefix) {
|
||||
return null;
|
||||
}
|
||||
this.getUserAlias(authResponse.details.username)
|
||||
.subscribe(data => { localStorage.setItem('alias',data.response);});
|
||||
localStorage.setItem('token', authResponse.token);
|
||||
localStorage.setItem('username', authResponse.details.username);
|
||||
}
|
||||
@@ -73,7 +66,6 @@ export class AuthService {
|
||||
private clearSession(): void {
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('username');
|
||||
localStorage.removeItem('alias')
|
||||
localStorage.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export const environment = {
|
||||
production: true
|
||||
production: true,
|
||||
server: 'https://132.2488.80.77:9707/'
|
||||
};
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
// The list of file replacements can be found in `angular.json`.
|
||||
|
||||
export const environment = {
|
||||
production: false
|
||||
production: false,
|
||||
server: 'https://192.168.0.7:9707/'
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user