Answers.Body: <p>To determine if the user is logged in at all, you'll want to use the <a href="http://buildwithcraft.com/docs/templating/global-variables#currentUser">currentUser</a> variable:</p>
  
  <pre><code>{% if currentUser %}
      Welcome, {{ currentUser.friendlyName }}!
  {% endif %}
  </code></pre>
  
  <p>To determine if the logged in user is a <em>specific</em> user, then simply compare against their username:</p>
  
  <pre><code>{% if currentUser and currentUser.username is 'johndoe' %}
      Hey Johnny Boy!
  {% endif %}
  </code></pre>
  
  <p>The <a href="http://buildwithcraft.com/docs/templating/usermodel#isCurrent">isCurrent</a> method is useful when targeting a more generic <a href="http://buildwithcraft.com/docs/templating/usermodel">UserModel</a> (where you don't know if the user would be the current user).</p>
  
  <pre><code>{% for user in craft.users %}
      {% if user.isCurrent %}
          {{ user.friendlyName }} is you!
      {% else %}
          {{ user.friendlyName }} is someone else.
      {% endif %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-20T18:21:55.350Z
Answers.Text: This works great thanks for clarifying. I did have an issue with using `is` in this context though: `Unexpected token "string" of value "bill" ("name" expected)` I swapped is with `==` and it seems to working fine now. Maybe some kind of typecast comparison issue?
Answers.UserDisplayName: Bill Columbia
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-20T18:29:55.283Z
Answers.Text: Huh, interesting... I wonder if it's just a grouping issue. Perhaps put parenthesis around the second part and try it as `if currentUser and (currentUser.username is 'johndoe')`. In theory, `is` should be parsed exactly the same as `==`. http://twig.sensiolabs.org/doc/templates.html#test-operator
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-20T18:34:41.277Z
Answers.Text: Here's another question addressing the topic of `is` vs `is same as` vs `==` vs `===` ... http://craftcms.stackexchange.com/questions/218/when-to-use-is-same-as-and-when-to-use
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-21T00:50:08.577Z
Answers.Text: @BillColumbia I just bumped into that same issue on a site I'm working on (`is` vs `==`), so I did a little more digging. It looks like `is` represents a "[test operator](http://twig.sensiolabs.org/doc/templates.html#test-operator)"... meaning, it runs **[tests](http://twig.sensiolabs.org/doc/tests/index.html)**. Meanwhile, `==` is a "[comparison operator](http://twig.sensiolabs.org/doc/templates.html#comparisons)". So, I learned something new today... `is` does not directly translate to `==`
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-20T18:01:40.970Z
Answers.LastActivityDate: 2014-06-20T18:13:29.947Z
Answers.LastEditDate: 2014-06-20T18:13:29.947Z
Answers.UserDisplayName: Lindsey D
Body: <p>I'm running some checks to see if there is a user logged in, and if that user is someone specific. When accessing <code>user.isCurrent</code> it's returning <code>1</code> when I'm logged in, but returns <code>null</code> when I'm not. Should this be returning <code>0</code> or false in that case, or should I be checking <code>{% if user.isCurrent is defined %}</code> ?</p>
  
Tags: <templating><users><current-user>
Title: How can I determine if a user is logged in, and who that user is?
ThreadText: # How can I determine if a user is logged in, and who that user is?
  
  (Asked by: username_0 on 2014-06-20)
  
  I'm running some checks to see if there is a user logged in, and if that user is someone specific. When accessing `user.isCurrent` it's returning `1` when I'm logged in, but returns `null` when I'm not. Should this be returning `0` or false in that case, or should I be checking `{% if user.isCurrent is defined %}` ?
  
  **Tags:** templating, users, current-user
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-06-20. Score: 29 | Accepted answer
  
  To determine if the user is logged in at all, you'll want to use the [currentUser](http://buildwithcraft.com/docs/templating/global-variables#currentUser) variable:
  
  ```
  {% if currentUser %}
      Welcome, {{ currentUser.friendlyName }}!
  {% endif %}
  
  ```
  
  To determine if the logged in user is a *specific* user, then simply compare against their username:
  
  ```
  {% if currentUser and currentUser.username is 'johndoe' %}
      Hey Johnny Boy!
  {% endif %}
  
  ```
  
  The [isCurrent](http://buildwithcraft.com/docs/templating/usermodel#isCurrent) method is useful when targeting a more generic [UserModel](http://buildwithcraft.com/docs/templating/usermodel) (where you don't know if the user would be the current user).
  
  ```
  {% for user in craft.users %}
      {% if user.isCurrent %}
          {{ user.friendlyName }} is you!
      {% else %}
          {{ user.friendlyName }} is someone else.
      {% endif %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: This works great thanks for clarifying. I did have an issue with using `is` in this context though: `Unexpected token "string" of value "username_0" ("name" expected)` I swapped is with `==` and it seems to working fine now. Maybe some kind of typecast comparison issue?  
  > **username_1**: Huh, interesting... I wonder if it's just a grouping issue. Perhaps put parenthesis around the second part and try it as `if currentUser and (currentUser.username is 'johndoe')`. In theory, `is` should be parsed exactly the same as `==`. http://twig.sensiolabs.org/doc/templates.html#test-operator  
  > **username_1**: Here's another question addressing the topic of `is` vs `is same as` vs `==` vs `===` ... http://craftcms.stackexchange.com/questions/218/when-to-use-is-same-as-and-when-to-use  
  > **username_1**: @username_0 I just bumped into that same issue on a site I'm working on (`is` vs `==`), so I did a little more digging. It looks like `is` represents a "[test operator](http://twig.sensiolabs.org/doc/templates.html#test-operator)"... meaning, it runs **[tests](http://twig.sensiolabs.org/doc/tests/index.html)**. Meanwhile, `==` is a "[comparison operator](http://twig.sensiolabs.org/doc/templates.html#comparisons)". So, I learned something new today... `is` does not directly translate to `==`  
  
  ---
  
  