diff --git a/client/scripts/controllers/login.controller.js b/client/scripts/controllers/login.controller.js new file mode 100644 index 0000000..6285e97 --- /dev/null +++ b/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: '
' + this.phone + '
Is your phone number above correct?
', + 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']; \ No newline at end of file