Code coverage report for app/components/login-form/login-form.controller.js

Statements: 100% (43 / 43)      Branches: 100% (14 / 14)      Functions: 100% (10 / 10)      Lines: 100% (19 / 19)      Ignored: 2 statements, 4 branches     

All files » app/components/login-form/ » login-form.controller.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                     
class LoginFormController {
    constructor (UserAPI, $state) {
        Object.assign(this, {UserAPI, $state});
    }
 
    login (credential) {
        const self = this;
        if (this.loginForm.$invalid) {
            return;
        }
        this.loginError = null;
        this.isRequest = true;
        this.UserAPI.login(credential.email, credential.password)
            .then(_success)
            .catch(_error);
 
        function _success () {
            // user was redirect to login page from other page
            if (self.$state.prev) {
                self.$state.go(self.$state.prev.state, self.$state.prev.params);
                self.$state.prev = null;
            } else {
                self.$state.go(self.routeAfterLogin);
            }
        }
 
        function _error (message) {
            self._setError('error', message.text);
            self.isRequest = false;
        }
    }
 
    _setError (type, text) {
        this.loginError = {
            type,
            text
        };
    }
}
 
LoginFormController.$inject = ['UserAPI', '$state'];
 
export default LoginFormController;