login.controller.js 997 B

1234567891011121314151617181920212223242526272829303132
  1. (function() {
  2. 'use strict';
  3. angular
  4. .module('cloudbudget')
  5. .controller('LoginController', LoginController);
  6. LoginController.$inject = ['$location', 'AuthenticationService', 'FlashService'];
  7. function LoginController($location, AuthenticationService, FlashService) {
  8. var vm = this;
  9. vm.login = login;
  10. (function initController() {
  11. AuthenticationService.clearCredentials();
  12. })();
  13. function login() {
  14. vm.dataLoading = true;
  15. AuthenticationService.login(vm.username, vm.password).then( function(response) {
  16. if( response.success ) {
  17. AuthenticationService.setCredentials(response.user);
  18. $location.path('/accounts');
  19. } else {
  20. FlashService.error(response.message);
  21. vm.dataLoading = false;
  22. }
  23. });
  24. }
  25. }
  26. })();