register.controller.js 1.1 KB

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