Move API call in dedicated service.
This commit is contained in:
parent
f12c89a9ee
commit
8ebe15f22f
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user