2016-11-22 85 views
0

我使用angularjs彈簧安全 我在app.js下面的代碼如何清除全球餅乾angularjs

 function run($rootScope, $location, $cookieStore, $http) { 
      // keep user logged in after page refresh 
      $rootScope.globals = $cookieStore.get('globals') || {}; 
      if ($rootScope.globals.currentUser) { 
       $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line 
      } 
    } 

當我按上登出我已經刪除當前用戶$ rootScope .globals.currentUser所以應用工作

我怎麼能做到這一點 我試圖通過Java代碼來刪除它

@RequestMapping(value = "/logout", method = RequestMethod.GET) 
    public String logout(HttpServletRequest request, HttpServletResponse response) { 

     HttpSession session= request.getSession(false); 
     SecurityContextHolder.clearContext(); 
      session= request.getSession(false); 
      if(session != null) { 
       session.invalidate(); 
      } 
      for(Cookie cookie : request.getCookies()) { 
       cookie.setMaxAge(0); 
      } 
     return "redirect:/j_spring_security_logout"; 
    } 
but It didn't work 
+0

顯然,'$ rootScope.globals.currentUser = NULL;'但是我想這不是你的問題......你能不能改一下它,請? – trichetriche

+0

http://stackoverflow.com/questions/26607856/how-to-remove-all-cookies-in-angularjs這是否工作? –

回答

0

你可以簡單地用角$餅乾業務,並刪除它像這樣:

$cookies.remove('coockieName');