// import { Component, OnInit } from '@angular/core'; // import { Router } from '@angular/router'; // import { NgForm } from '@angular/forms'; // import { LoadingController, AlertController } from '@ionic/angular'; // import { Observable } from 'rxjs'; // import { AuthService, AuthResponseData } from './auth.service'; // @Component({ // selector: 'app-auth', // templateUrl: './auth.page.html', // styleUrls: ['./auth.page.scss'] // }) // export class AuthPage implements OnInit { // isLoading = false; // isLogin = true; // constructor( // private authService: AuthService, // private router: Router, // private loadingCtrl: LoadingController, // private alertCtrl: AlertController // ) {} // ngOnInit() {} // authenticate(email: string, password: string) { // // this.isLoading = true; // // this.loadingCtrl // // .create({ keyboardClose: true, message: 'Logging in...' }) // // .then(loadingEl => { // // loadingEl.present(); // // let authObs: Observable; // // if (this.isLogin) { // // authObs = this.authService.login(email, password); // // } else { // // authObs = this.authService.signup(email, password); // // } // // authObs.subscribe( // // resData => { // // console.log(resData); // // this.isLoading = false; // // loadingEl.dismiss(); // // this.router.navigateByUrl('/places/tabs/discover'); // // }, // // errRes => { // // loadingEl.dismiss(); // // const code = errRes.error.error.message; // // let message = 'Could not sign you up, please try again.'; // // if (code === 'EMAIL_EXISTS') { // // message = 'This email address exists already!'; // // } else if (code === 'EMAIL_NOT_FOUND') { // // message = 'E-Mail address could not be found.'; // // } else if (code === 'INVALID_PASSWORD') { // // message = 'This password is not correct.'; // // } // // this.showAlert(message); // // } // // ); // // }); // } // onSwitchAuthMode() { // this.isLogin = !this.isLogin; // } // onSubmit(form: NgForm) { // if (!form.valid) { // return; // } // const email = form.value.email; // const password = form.value.password; // this.authenticate(email, password); // form.reset(); // } // private showAlert(message: string) { // this.alertCtrl // .create({ // header: 'Authentication failed', // message: message, // buttons: ['Okay'] // }) // .then(alertEl => alertEl.present()); // } // } import { Component } from '@angular/core'; import { LoadAlertsService } from 'src/app/services/load-alerts.service'; import { StorageService } from 'src/app/services/storage.service'; import { UserService } from 'src/app/services/user.service'; import { RouterService } from 'src/app/services/router.service'; import { Platform,AlertController } from '@ionic/angular'; @Component({ selector: 'app-home', templateUrl: 'auth.page.html', styleUrls: ['auth.page.scss'], }) export class AuthPage { constructor( private User:UserService, private router:RouterService, private loadAlertsService:LoadAlertsService, private storage:StorageService, private plt:Platform ) { } accept; UserName:string; PWD:string; signupPWD:string; lang; /*{ text: 'Cancel', role: 'cancel', handler: (blah) => { console.log('Confirm Cancel: blah'); } }, { text: 'Okay', handler: () => { console.log('Confirm Okay'); } }*/ ionViewWillEnter(){ this.plt.ready().then(() => { this.plt.backButton.subscribeWithPriority(9999999, () => { this.router.exitApp(); }) }); this.storage.get("lang").then(data=>{console.log(data,'lang'); this.lang=data; if(data==2) { document.dir='rtl' } else { document.dir='ltr' } }, error=>{console.log(error,'langError');}); } IsSignUp; CreateAccount(){ this.IsSignUp=1; } back() { this.IsSignUp=undefined; } SignUpFn(){ if(this.accept==true){ if(this.signupPWD!='' && this.signupPWD!=undefined) { let body={ request_category : 'sign_up', oss_language : this.lang==1?'en':'ar', oss_secret :this.signupPWD }; console.log(body); this.loadAlertsService.presentLoading('Please Wait...'); this.User.SignUp(body).subscribe(data=>{ this.loadAlertsService.dismissLoading(); console.log(data,"data"); this.router.navByUrl("layout/main"); },error=>{ this.loadAlertsService.dismissLoading(); console.log(error,'error'); }); } else{ this.loadAlertsService.PresentAlert("","Attention",'Password cannot be empty.') } }else{ this.loadAlertsService.PresentAlert("","Attention",'You have to accept the terms and conditions first.') } } ionViewWillLeave(){ this.plt.ready().then(() => { this.plt.backButton.subscribeWithPriority(9999999, () => { this.router.goBack(); }) }); } SubmitFn(){ let body={ request_category : 'sign_in', oss_language :this.lang==1?'en':'ar', oss_username :this.UserName, oss_secret:this.PWD }; //console.log(body); // this.router.navByUrl("layout/main"); if(this.PWD==undefined || this.PWD=='') { this.loadAlertsService.PresentAlert("","Attention",'Password cannot be empty.') }else{ if(this.UserName==undefined || this.UserName=='') { this.loadAlertsService.PresentAlert("","Attention",'User Name cannot be empty.') }else{ this.loadAlertsService.presentLoading('Please Wait...'); this.User.SignIn(body).subscribe(data=>{ if(data.response_result==0){ this.loadAlertsService.PresentAlert("","Attention",data.response_message); this.loadAlertsService.dismissLoading(); } else{ console.log('signinsuccess'); this.loadAlertsService.dismissLoading(); this.router.navByUrl("layout/main"); } // console.log(data,"data"); },error=>{ this.loadAlertsService.dismissLoading(); console.log(error,'error'); }); } } } }