Code coverage report for app/pages/login/login.controller.js

Statements: 100% (26 / 26)      Branches: 100% (4 / 4)      Functions: 100% (7 / 7)      Lines: 100% (17 / 17)      Ignored: 1 statement, 1 branch     

All files » app/pages/login/ » login.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                                                 
class LoginController {
    constructor (UserAPI, $state, $timeout) {
        Object.assign(this, {UserAPI, $state, $timeout});
 
        this.routeAfterLogin = 'root.layout.dashboard';
 
        // handle logout
        const action = this.$state.params.action;
        if (action === 'logout') {
            this.needCheckLogin = false;
            this.UserAPI.logout()
                .then(() => {
                    this.loginError = {
                        type: 'success',
                        text: 'You have been successfully logged out!'
                    };
                });
        } else {
            this.userInfo = null;
            this.needCheckLogin = true;
            const self = this;
            // check login status firstly
            this.UserAPI.checkLoggedInStatus()
                .then((data) => {
                    self.userInfo = data;
                    self.$timeout(() => {
                        self.$state.go(self.routeAfterLogin);
                    }, 1000);
                })
                .catch(() => {
                    self.needCheckLogin = false;
                });
        }
    }
}
 
LoginController.$inject = ['UserAPI', '$state', '$timeout'];
 
export default LoginController;