Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. .state('app', {
  2. url:'/',
  3. abstract: true,
  4. views:{
  5. 'bodyLogin': {templateUrl : 'views/login/body.html',
  6. controller : 'BodyController'},
  7. 'bodyMain': {templateUrl : 'views/main/body.html',
  8. controller : 'BodyController'}}
  9. })
  10. .state('app.mainUnreg', {
  11. url:'home',
  12. views: {
  13. 'content@app': {
  14. templateUrl : 'views/login/home.html'
  15. }}})
  16. .state('app.mainReg', {
  17. url:'mainMenu',
  18. views: {
  19. 'header@app': {
  20. templateUrl : 'views/main/header.html'
  21. },
  22. 'sidebar@app': {
  23. templateUrl : 'views/main/sidebar.html'
  24. },
  25. 'middle@app': {
  26. templateUrl : 'views/main/home.html'
  27. },
  28. 'footer@app': {
  29. templateUrl : 'views/main/footer.html'
  30. }},
  31. controller: 'HomeController'})
  32.  
  33. <div ng-if="!loggedIn" ui-view="bodyLogin" class="site-wrapper" ui-sref-active="app.mainUnreg"></div>
  34. <div ng-if="loggedIn" ui-view="bodyMain" ui-sref-active="app.mainReg"></div>
  35.  
  36. .controller('BodyController', [..., function(...){
  37. //this line is to check whether the user has been authenticated or not
  38. if(Account.isAuthenticated() === false) {
  39. $scope.loggedIn = false;}
  40. // ------------
  41.  
  42. if($scope.loggedIn === false){
  43. $scope.layout = 'login';
  44. $state.go('app.mainUnreg');
  45. }
  46. else{$scope.loggedIn = true;
  47. $scope.layout = 'styles';
  48. $state.go('app.mainReg');
  49. }}])
  50.  
  51. .controller('LoginController', [..., function (...) { $currentUserId = Account.getCurrentId();
  52. $scope.$stateParams = $stateParams; $scope.loginData = {}; $scope.doLogin = function() { AuthService.login($scope.loginData)
  53. .then(function() {
  54. $scope.loggedIn = true;
  55. location.reload(); }); };}])
  56.  
  57. .controller('LogoutController', [..., function(...) {
  58. AuthService.logout()
  59. .then(function() {
  60. console.log("Logging out . . .");
  61. $scope.loggedIn = false;
  62. $state.go('app'); }); }]);
  63. And some additional service beside lb-services.js to handle my authentication,
  64.  
  65. function login(loginData) {
  66. var params = { rememberMe: loginData.rememberMe };
  67. var credentials = {
  68. email: loginData.email,
  69. password : loginData.password
  70. };
  71. return User
  72. .login(params, credentials)
  73. .$promise.then(function(response){ $rootScope.currentUser = {...};
  74. console.log($rootScope.currentUser);
  75. },
  76. function(response) {
  77. console.log(response);
  78. });
  79. }
  80. function logout(){
  81. return User
  82. .logout()
  83. .$promise.then(function(){
  84. $rootScope.currentUser = null;
  85. });
  86. };
  87.  
  88. if(Account.isAuthenticated() === false){...}
  89.  
  90. $LoopBack$accessTokenId = ....
  91. $LoopBack$currentUserId = ...
  92. $LoopBack$rememberMe = true // automatically become true?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement