Skip to content

Commit

Permalink
Step 4.7: Add login controller
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 23, 2016
1 parent 6b7e87f commit a4dfce1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions client/scripts/controllers/login.controller.js
@@ -0,0 +1,46 @@
import { _ } from 'meteor/underscore';
import { Accounts } from 'meteor/accounts-base';
import { Controller } from 'angular-ecmascript/module-helpers';

export default class LoginCtrl extends Controller {
login() {
if (_.isEmpty(this.phone)) return;

const confirmPopup = this.$ionicPopup.confirm({
title: 'Number confirmation',
template: '<div>' + this.phone + '</div><div>Is your phone number above correct?</div>',
cssClass: 'text-center',
okText: 'Yes',
okType: 'button-positive button-clear',
cancelText: 'edit',
cancelType: 'button-dark button-clear'
});

confirmPopup.then((res) => {
if (!res) return;

this.$ionicLoading.show({
template: 'Sending verification code...'
});

Accounts.requestPhoneVerification(this.phone, (err) => {
this.$ionicLoading.hide();
if (err) return this.handleError(err);
this.$state.go('confirmation', { phone: this.phone });
});
});
}

handleError(err) {
this.$log.error('Login error ', err);

this.$ionicPopup.alert({
title: err.reason || 'Login failed',
template: 'Please try again',
okType: 'button-positive button-clear'
});
}
}

LoginCtrl.$name = 'LoginCtrl';
LoginCtrl.$inject = ['$state', '$ionicLoading', '$ionicPopup', '$log'];

0 comments on commit a4dfce1

Please sign in to comment.