Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login() {
- this.Loading("","send");
- this.http.postData(this.userData, "post/login").subscribe( result => {
- this.responseData = result;
- if (this.responseData.success) {
- localStorage.setItem('userSesion', JSON.stringify(this.responseData.dataUser));
- if (this.responseData.dataUser.tipo === '1') {
- this.navCtrl.setRoot(InicioPage);
- } else if (this.responseData.dataUser.tipo === '2') {
- this.navCtrl.setRoot(IniciodocentePage);
- }
- } else {
- this.Loading(this.responseData.dataUser,"error");
- }
- }, (err) => {
- console.log(err);
- });
- }
- export class MyApp {
- @ViewChild(Nav) nav: Nav;
- rootPage: any = HomePage;
- pages: Array<{title: string, component: any}>;
- public sesion:boolean;
- public opt:boolean;
- userDetails:any = {};
- constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen) {
- this.initializeApp();
- if (localStorage.getItem('userSesion')) {
- const data = JSON.parse(localStorage.getItem('userSesion'));
- this.userDetails = data;
- this.sesion = true;
- if (this.userDetails.tipo == '1') {
- this.pages = [
- { title: 'Inicio', component: InicioPage },
- { title: 'Registro de Inscripción', component: CarrerasestudiantePage },
- { title: 'Historial Academico', component: HistoricoPage },
- { title: 'Procesar Inscripción', component: ProcesarinscripcionPage }
- ];
- } else if (this.userDetails.tipo == '2') {
- this.pages = [
- { title: 'Inicio', component: IniciodocentePage },
- { title: 'Mi Carga Académica', component: CargaacademicaprofesorPage }
- ];
- }
- } else {
- this.pages = [
- { title: 'Entrar', component: HomePage },
- { title: 'Olvide mi clave', component: AboutPage },
- { title: 'Consultar Estatus', component: ContactPage }
- ];
- this.sesion = false;
- }
- }
- initializeApp() {
- this.platform.ready().then(() => {
- this.statusBar.styleDefault();
- this.splashScreen.hide();
- });
- }
- openPage(page) {
- this.nav.setRoot(page.component);
- }
- }
- export class User {
- username: string;
- email: string;
- password: string;
- tokens: Array<Token> = [];
- constructor(username, password, email = '') {
- this.username = username;
- this.email = email;
- this.password = password;
- }
- }
- //user.service.ts
- import { BehaviorSubject, Observable } from 'rxjs';
- export class UserService {
- user: User;
- private userSubject = new BehaviorSubject(this.user);
- // Lo demas componentes se ponen a la esucha de cambio
- // a través de esté método
- getUserObservable(): Observable<User> {
- return this.userSubject.asObservable();
- }
- // Este método se usa para enviar los cambios a todos los componentes a la escucha
- private setUser(user: User) {
- this.user = user;
- // Refrescar user en los observables
- this.userSubject.next(this.user);
- }
- }
- import {UserService} from 'user.service'
- export class Menu {
- user: User;
- constructor(userService:UserService){
- // REGISTRASE AL OBSERVABLE DE UserService
- // para estar a la escucha de cambios de user
- this.userService.getUserObservable().subscribe(
- (data) => {
- this.user = data;
- }, (error) => {
- console.log(error);
- });
- }
- }
Add Comment
Please, Sign In to add comment