import Controller from '@ember/controller'; import { inject as service } from '@ember/service'; import { computed } from '@ember/object'; export default Controller.extend({ session: service('session'), errors : service(), cordovaEvents: service('ember-cordova/events'), classDisable:"", init() { this._super(...arguments); this.get('cordovaEvents').on('deviceready', this, '_initStatusBar'); }, _initStatusBar: function() { if (window.cordova.platformId == 'ios') { if (window.StatusBar != undefined) { window.StatusBar.overlaysWebView(false); window.StatusBar.backgroundColorByHexString('#212529'); } } }, userinfo: computed('identification','password', function() { let identificationExist = false; if (this.identification != "" && this.identification != null && this.identification != undefined) { identificationExist = true; } let passwordExist = false; if (this.password != "" && this.password != null && this.password != undefined) { passwordExist = true; } if (identificationExist && passwordExist) return true; return false; }), actions: { authenticateWithOAuth2() { if (!this.userinfo) { this.set('errorMessage', "Username and Password is required"); return; } let { identification, password } = this.getProperties('identification', 'password'); //this.set('errorMessage', ''); this.get('session').authenticate('authenticator:oauth2', identification, password) .catch((e) => { if(e != null) { console.log(e); if (e.status == 401) { //this.set('errorMessage', 'Username or Password Incorrect'); if(e.responseJSON.errors[0].title == ""){ this.set('errorMessage', 'Username or Password Incorrect'); }else{ this.set('errorMessage',e.responseJSON.errors[0].title); } } else { console.log(e); this.set('errorMessage', this.errors.getErrorMessages(e)); } } else { this.set('errorMessage', "Error Occured"); } }); } } });