From 8ebe15f22fe35b55cd86fa0a77112ac094b7d1a8 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 14 Oct 2016 08:50:54 +0200 Subject: [PATCH] Move API call in dedicated service. --- accountant-ui/js/app.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) 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);