Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- import { NavController, ModalController, LoadingController, AlertController, ToastController } from 'ionic-angular';
- import { RegisterPage } from '../register/register';
- import { HomePage } from '../home/home';
- import { UsersService } from '../../providers/users-service';
- /*
- Generated class for the Login page.
- See http://ionicframework.com/docs/v2/components/#navigation for more info on
- Ionic pages and navigation.
- */
- @Component({
- selector: 'page-login',
- templateUrl: 'login.html',
- providers: [UsersService]
- })
- export class LoginPage {
- public emailField: any;
- public passwordField: any;
- private users = [];
- private usersList : any;
- constructor(private alertCtrl: AlertController, private loadingCtrl: LoadingController, private modalCtrl: ModalController, public navCtrl: NavController, private usersService: UsersService, private toastCtrl: ToastController) {
- this.emailField="bokeefe08@gmail.com";
- this.listOurUsers();
- }
- signUpUser() {
- this.usersService.signUpUser(this.emailField, this.passwordField).then(authData => {
- //successful
- this.navCtrl.setRoot(HomePage);
- }, error => {
- //alert("Error logging in:"+ error.message);
- let alert = this.alertCtrl.create({
- title: 'Error logging in',
- subTitle: error.message,
- buttons: ['OK']
- });
- alert.present();
- });
- let loader = this.loadingCtrl.create({
- dismissOnPageChange: true,
- });
- loader.present();
- }
- listOurUsers() {
- this.usersService.loadUser(10)
- .then(data => {
- this.usersList = data;
- })
- }
- submitLogin (){
- this.usersService.loginUser(this.emailField, this.passwordField).then(authData => {
- //successful
- this.navCtrl.setRoot(HomePage);
- }, error => {
- //alert("Error logging in:"+ error.message);
- let alert = this.alertCtrl.create({
- title: 'New Friend!',
- subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
- buttons: ['OK']
- });
- alert.present();
- });
- }
- submitRegister (){
- let registerModal = this.modalCtrl.create(RegisterPage);
- registerModal.present();
- }
- showForgotPassword() {
- //
- let prompt = this.alertCtrl.create({
- title: 'Enter Your Email',
- message: "A new password will be sent to your email",
- inputs: [
- {
- name: 'recoverEmail',
- placeholder: 'you@example.com'
- },
- ],
- buttons: [
- {
- text: 'Cancel',
- handler: data => {
- console.log('Cancel clicked');
- }
- },
- {
- text: 'Submit',
- handler: data => {
- //add preloader
- let loading = this.loadingCtrl.create({
- dismissOnPageChange: true,
- content: 'Reseting your password..'
- });
- loading.present();
- //call userservice
- this.usersService.forgotUserPassword(data.recoverEmail).then(() => {
- //add toast
- loading.dismiss().then(() => {
- //show pop-up
- let alert = this.alertCtrl.create({
- title: 'Password Reset Successful',
- subTitle: 'Please check your email',
- buttons: ['OK']
- });
- alert.present();
- })
- }, error => {
- //show pop-up
- loading.dismiss().then(() => {
- let alert = this.alertCtrl.create({
- title: 'Error resetting password',
- subTitle: error.message,
- buttons: ['OK']
- });
- alert.present();
- })
- });
- }
- }
- ]
- });
- prompt.present();
- }
- googleSignIn(){
- this.usersService.googleSignInUser().then(()=>{
- //success, redirect
- let toast = this.toastCtrl.create({
- message: 'User account created successfully...',
- duration: 3000
- });
- toast.present();
- });
- }
- ionViewDidLoad() {
- console.log('Hello Login Page');
- }
- }
Add Comment
Please, Sign In to add comment