Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. angular.module('edc-service.controllers', [])
  2.  
  3. .controller('AppCtrl', ['$scope', '$state', 'authService', function($scope, $state, authService) {
  4. $scope.logout = function() {
  5. $state.go('login');
  6. authService.clearUser();
  7. };
  8.  
  9. // Perform the login action when the user submits the login form
  10. $scope.doLogin = function() {
  11. console.log('Doing login', $scope.loginData);
  12.  
  13. // Simulate a login delay. Remove this and replace with your login
  14. // code if using a login system
  15. $timeout(function() {
  16. $scope.closeLogin();
  17. }, 1000);
  18. };
  19. }])
  20.  
  21. .controller('JobsCtrl', ['$scope', '$state', 'jobFactory', 'authService',
  22. function($scope, $state, jobFactory, authService) {
  23.  
  24. var jobs = this;
  25.  
  26. $scope.$on('$ionicView.loaded', function () {
  27. var user = authService.currentUser();
  28.  
  29. if (!user) {
  30. $state.go('login');
  31. }
  32. else {
  33. jobs.getJobs(user);
  34. }
  35. });
  36.  
  37. jobs.getJobs = function (user) {
  38. jobs.loading = true;
  39. jobFactory.getJobs(user)
  40. .then(function (data) {
  41. jobs.jobList = data;
  42. jobs.loading = false;
  43. })
  44. .then(function (error) {
  45. jobs.loading = false;
  46. });
  47. }
  48.  
  49. }])
  50.  
  51. .controller('ProfileCtrl', ['$scope', '$state', 'authService',
  52. function($scope, $state, authService) {
  53.  
  54. var profile = this;
  55.  
  56. $scope.$on('$ionicView.loaded', function () {
  57. profile.user = authService.currentUser();
  58.  
  59. if (!profile.user) {
  60. $state.go('login');
  61. }
  62. });
  63. }])
  64.  
  65.  
  66. .controller('LoginCtrl', ['$scope', '$state', 'apiURL', 'contactInfo', 'authService',
  67. function($scope, $state, apiURL, contactInfo, authService) {
  68.  
  69. var login = this;
  70.  
  71. $scope.$on('$ionicView.loaded', function () {
  72. login.loading = true;
  73. login.user = {
  74. userName: "skempner",
  75. password: "experian.1"
  76. }
  77.  
  78. login.contactInfo = contactInfo;
  79. login.loading = false;
  80. });
  81.  
  82. login.login = function (user) {
  83. login.loading = true;
  84. authService.login(user)
  85. .then (function (data) {
  86. login.password = "";
  87. $state.go("app.jobs");
  88. login.loading = false;
  89. })
  90. .then (function (error) {
  91. login.loading = false;
  92. });
  93. }
  94.  
  95. }])
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement