diff --git a/accountant-ui/js/app.js b/accountant-ui/js/app.js index fe4f923..1520f9d 100644 --- a/accountant-ui/js/app.js +++ b/accountant-ui/js/app.js @@ -91,7 +91,20 @@ angular.module('accountant', [ editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default' }) -.controller('MainController', function($rootScope, $http, authService, $storage, $ngBootbox) { +.service('LoginService', function($http) { + var login = function(email, password) { + return $http.post('/api/user/login', { + email: email, + password: password + }); + }; + + return { + 'login': login + }; +}) + +.controller('MainController', function($rootScope, LoginService, authService, $storage, $ngBootbox) { var vm = this; vm.dialogShown = false; @@ -118,13 +131,7 @@ angular.module('accountant', [ var email = $('#email').val(); var password = $('#password').val(); - $http.post( - '/api/user/login', - { - email: email, - password: password - } - ).success(function(result) { + LoginService.login(email, password).success(function(result) { // TODO Alexis Lahouze 2015-08-28 Handle callback. // Call to /api/login to retrieve the token $storage.set('token_type', result.token_type);