title: How to know if the user is logged in (in the GSP)
body: <p>I have <code>index.gsp</code> that presents a page. In that page there is a button to register, and a button to log in. Once you have logged in, if the login is ok, the app drives you again to <code>index.gsp</code>. I need that, if the user is logged in, these buttons disappear, and instead say "Hello, [username]". I've tried with this code, but it doesn't work (it is never logged in):</p>
  
  <p>In the Controller:</p>
  
  <pre><code>def dologin(){
  
      def user=Usuario.findByUsernameAndPassword(params.username,springSecurityService.encodePassword(params.password) )
  
      if(user){
          redirect (controller:'usuario', action:'index')
      }else{
  
          flash.message=message(code:'default.user.not.found', args:[message(code: 'params.username', default:'Usuario'), params.id])
      def userlogged = springSecurityService.getCurrentUser()
                  render view: 'index', model: [user: user]
  }
  
  }
  </code></pre>
  
  <p>In index.gsp (is not full, only the piece that matters):</p>
  
  <pre><code>&lt;sec:ifNotLoggedIn&gt;
  
  &lt;div id="buttons"&gt;
      &lt;div id="login"&gt;&lt;a href="loginurl"&gt;Login&lt;/a&gt;
      &lt;/div&gt;
      &lt;div id="register"&gt;&lt;a href="registerurl"&gt;Registrarse&lt;/a&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/sec:ifNotLoggedIn&gt;
  &lt;sec:ifLoggedIn&gt;
  
  &lt;div id="greet"&gt;Hello!&lt;/div&gt; 
  
  &lt;/sec:ifLoggedIn&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thank you.</p>