Created
February 25, 2019 18:49
-
-
Save Sampath-Lokuge/c1b74ea0a8e56c942915647222d89f98 to your computer and use it in GitHub Desktop.
Login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { FormGroup, FormBuilder, Validators } from '@angular/forms'; | |
import { NavController } from '@ionic/angular'; | |
import { ShowToastService } from 'src/app/services/show-toast.service'; | |
import { LoadingService } from 'src/app/services/loading.service'; | |
import { AuthenticationService } from 'src/app/services/authentication.service'; | |
@Component({ | |
selector: 'app-login', | |
templateUrl: './login.page.html', | |
styleUrls: ['./login.page.scss'], | |
}) | |
export class LoginPage implements OnInit { | |
form: FormGroup; | |
constructor(private formBuilder: FormBuilder, | |
private navCtrl: NavController, | |
private showToastService: ShowToastService, | |
private loadingService: LoadingService, | |
private authenticationService: AuthenticationService) { | |
this.init(); | |
} | |
ngOnInit() { | |
} | |
init() { | |
this.form = this.formBuilder.group({ | |
email: ['', Validators.required], | |
password: ['', Validators.compose([Validators.minLength(8), Validators.required])], | |
}); | |
} | |
async signIn() { | |
if (!this.form.valid) { | |
this.showToastService.showErrorToast('Please enter valid email and password'); | |
} else { | |
const loading = await this.loadingService.presentLoader(); | |
try { | |
await this.authenticationService.signIn(this.form.value.email, this.form.value.password); | |
this.loadingService.dismissLoader(loading); | |
this.navCtrl.navigateForward('/my-profile'); | |
} catch (error) { | |
this.loadingService.dismissLoader(loading); | |
console.log(error); | |
} | |
} | |
} | |
async loginWithFacebook() { | |
const loading = await this.loadingService.presentLoader(); | |
try { | |
await this.authenticationService.loginWithFacebook(); | |
this.navCtrl.navigateForward('/my-profile'); | |
this.loadingService.dismissLoader(loading); | |
} catch (error) { | |
this.loadingService.dismissLoader(loading); | |
console.log(error); | |
} | |
} | |
async loginWithGoogle() { | |
const loading = await this.loadingService.presentLoader(); | |
try { | |
await this.authenticationService.loginWithGoogle(); | |
this.navCtrl.navigateForward('/my-profile'); | |
this.loadingService.dismissLoader(loading); | |
} catch (error) { | |
this.loadingService.dismissLoader(loading); | |
console.log(error); | |
} | |
} | |
goToSignUp() { | |
this.navCtrl.navigateForward('/signup'); | |
} | |
goToResetPassword() { | |
this.navCtrl.navigateForward('/reset-password'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment