Move API call in dedicated service.

This commit is contained in:
Alexis Lahouze 2016-10-14 08:50:54 +02:00
parent f12c89a9ee
commit 8ebe15f22f

View File

@ -91,7 +91,20 @@ angular.module('accountant', [
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default' 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; var vm = this;
vm.dialogShown = false; vm.dialogShown = false;
@ -118,13 +131,7 @@ angular.module('accountant', [
var email = $('#email').val(); var email = $('#email').val();
var password = $('#password').val(); var password = $('#password').val();
$http.post( LoginService.login(email, password).success(function(result) {
'/api/user/login',
{
email: email,
password: password
}
).success(function(result) {
// TODO Alexis Lahouze 2015-08-28 Handle callback. // TODO Alexis Lahouze 2015-08-28 Handle callback.
// Call to /api/login to retrieve the token // Call to /api/login to retrieve the token
$storage.set('token_type', result.token_type); $storage.set('token_type', result.token_type);