Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Home.ts
- role: any;
- refresh:boolean = false;
- constructor() {
- let role = {
- admin: false,
- user: false,
- guest: true
- };
- this.role = role;
- this.checkRole();
- }
- checkRole() {
- this.getRole().then((role) => {
- this.role = role;
- if (this.role.guest == false && this.refresh == true) {
- this.refreshPage();
- }
- }, (err) => {
- console.log("Error: " + err);
- this.checkRole();
- });
- }
- ngOnInit() {
- console.log("Refrescando");
- let refresh = this.navParams.get('id');
- this.refresh = refresh;
- console.log(refresh);
- }
- //Login.ts
- user: any;
- pass: any;
- data: any;
- constructor() {
- this.user = "";
- this.pass = "";
- this.data = "";
- }
- login() {
- var err:boolean = true;
- if (this.user == "") {
- this.activeToast("No puedes dejar el usuario en blanco");
- } else if (this.pass == "") {
- this.activeToast("No puedes dejar la contraseña en blanco");
- } else {
- this.fetchData().subscribe((data) => {
- for (var i = 0;i<data.length;i++) {
- if (this.user == data[i].user) {
- if (this.pass == data[i].pass) {
- err = false;
- if (data[i].role == "user")
- this.globalservices.loginUser();
- else
- this.globalservices.loginAdmin();
- }
- }
- }
- if (err) {
- this.activeToast("Usuario o contraseña incorrectos");
- } else {
- this.activeToast("Has iniciado sesion correctamente");
- this.nav.popToRoot();
- this.nav.push(HomePage);
- }
- });
- }
- }
- fetchData() {
- return this.http.get("assets/data.json").map((res:Response) => res.json().data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement