(function () { 'use strict'; angular .module('app') .controller('LoginController', login); function login(accountRepository, authorizeHelper, stateHandler, appSettings, errorHandler, uiNotifications, localizationHelper) { /* jshint validthis:true */ var vm = this; if (appSettings.DEVELOPMENT) { vm.login = {email: 'superadmin@gmail.com', password: 'superadmin'}; } else { vm.login = {email: '', password: ''}; } vm.setLanguage = function(langCode){ localizationHelper.setLanguage(langCode); } vm.loginSubmit = function () { accountRepository.login(vm.login).success(function(response, status, headers, config){ if (errorHandler.check(response, status, config) == errorHandler.STATUS.SUCCESS) { // Save user role, name, id from response into the localStorage. authorizeHelper.setUserRules(response); // Define the previous url and redirect if needed. stateHandler.goto(); }else if (response && !response.success) { uiNotifications.inform(response.message,'error'); } }); }; } // IoC container. login.$inject = [ "repository.account", "helpers.authorize", "appUtils.stateHandler", "app.SETTINGS", "appUtils.errorHandler", "appUtils.uiNotifications", "helpers.localization" ]; })();