Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. .controller('BodyController', ['Account', '$scope', '$state', '$stateParams', '$rootScope', 'AuthService', function(Account, $scope, $state, $stateParams, $rootScope, AuthService){
  2.  
  3. $rootScope.$state = $state;
  4. $rootScope.$stateParams = $stateParams;
  5.  
  6. if(Account.isAuthenticated() == false) {
  7. $scope.loggedIn = false;
  8. }
  9.  
  10. if($scope.loggedIn === false){
  11. $scope.layout = 'login';
  12. $state.go('app.mainUnreg');
  13. }
  14. else{
  15. $scope.loggedIn = true;
  16. $scope.layout = 'styles';
  17. $state.go('app.mainReg');
  18. }
  19. }])
  20. .controller('LoginController', ['Account','$scope', '$state', '$stateParams', 'AuthService', '$rootScope', '$route', '$routeParams', '$location', function (Account, $scope, $state, $stateParams, AuthService, $rootScope, $currentUserId, $route, $routeParams, $location) {
  21.  
  22. $currentUserId = Account.getCurrentId();
  23. $scope.$stateParams = $stateParams;
  24.  
  25. $scope.loginData = {
  26. email: 'testing@gmail.com',
  27. password: 'Abc123456',
  28. };
  29.  
  30. $scope.doLogin = function() {
  31. console.log('Logging in as ', $scope.loginData.email);
  32.  
  33. AuthService.login($scope.loginData)
  34. .then(function() {
  35. $scope.loggedIn = true;
  36. $stateParams.userID = Account.getCurrentId();
  37. console.log($stateParams.userID);
  38. $state.go('app.mainReg', {param: Account.getCurrentId()});
  39. $route.reload();
  40. });
  41. };
  42. }])
  43.  
  44. .state('app', {
  45. url:'/',
  46. abstract: true,
  47. vie
  48.  
  49. ws:{
  50. 'bodyLogin': {
  51. templateUrl : 'views/login/body.html',
  52. controller : 'BodyController'
  53. },
  54. 'bodyMain': {
  55. templateUrl : 'views/main/body.html',
  56. controller : 'BodyController'
  57. }
  58. }
  59. })
  60. .state('app.mainUnreg', {
  61. url:'home',
  62. views: {
  63. 'content@app': {
  64. templateUrl : 'views/login/home.html',
  65. controller : ''
  66. }
  67. }
  68. })
  69. .state('app.mainReg', {
  70. url:':userID',
  71. views: {
  72. 'header@app': {
  73. templateUrl : 'views/main/header.html',
  74. controller : ''
  75. },
  76. 'sidebar@app': {
  77. templateUrl : 'views/main/sidebar.html',
  78. controller : ''
  79. },
  80. 'middle@app': {
  81. templateUrl : 'views/main/home.html',
  82. controller : ''
  83. },
  84. 'footer@app': {
  85. templateUrl : 'views/main/footer.html',
  86. controller : ''
  87. }
  88. },
  89. controller: 'MainController',
  90. resolve: {
  91. myResolve1:
  92. function($http, $stateParams) {
  93. return $http.get("/api/accounts/"+ Account.getCurrentId());
  94. }
  95. }
  96. })
  97.  
  98. <div ng-if="!loggedIn" ui-view="bodyLogin" class="site-wrapper" ui-sref-active="app.mainUnreg"></div>
  99.  
  100. <div ng-if="loggedIn" ui-view="bodyMain" ui-sref-active="app.mainReg"></div>
  101.  
  102. function login(loginData) {
  103. var params = { rememberMe: loginData.rememberMe };
  104. var credentials = {
  105. email: loginData.email,
  106. password : loginData.password
  107. };
  108. return User
  109. .login(params, credentials)
  110. .$promise.then(function(response){
  111.  
  112. $rootScope.currentUser = {
  113. tokenId: response.id,
  114. email: response.email
  115. };
  116. },
  117. function(response) {
  118. console.log(response);
  119. });
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement