Answers.Body: <p>Currently, Craft doesn't expose the UID in any of its models.</p>
  
  <p>Kind of a pain, but the only thing I can think of as as a workaround is to write a plugin that has a UserModel with the UID and mimics whatever methods from UsersService that you need.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-26T05:53:35.510Z
Answers.Text: thanks brad, kinda a pain but yeah ill do a workaround.
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-26T05:55:26.150Z
Answers.Text: Entirely possible we expose UID to the UserModel at some point, too. Will have to think about any side-effects from doing so.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-26T05:58:21.277Z
Answers.Text: i understand security concerns... just as a little background on what I am building: a link in an email that contains the users UID within the link as well as a one time use code to log the user in directly from the email link using userSession->impersonate(). I just wanted to use the UID and Code not the userId and Code -  as the userId is guessable.
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-26T04:47:19.017Z
Answers.LastActivityDate: 2014-11-26T05:12:04.390Z
Answers.LastEditDate: 2014-11-26T05:12:04.390Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>If you want to get a user model based on UID you can do this. </p>
  
  <p>For current user..</p>
  
  <ol>
  <li>Get current user <code>$currentUser = craft()-&gt;userSession-&gt;getUser();</code></li>
  <li>Get user record <code>$currentUserRecord = $this-&gt;_getUserRecordById($currentUser-&gt;id);</code></li>
  <li><p>Add this private function (copied from UserService.php). This will pull the user record by calling <code>_getUserRecordById</code> function</p>
  
  <pre><code>private function _getUserRecordById($userId)
  {
    $userRecord = UserRecord::model()-&gt;findById($userId);
    if (!$userRecord) {
      throw new Exception(Craft::t('No user exists with the ID “{id}”.', array('id' =&gt; $userId)));
  }
  
  return $userRecord;
  }
  </code></pre></li>
  <li>Now get user UID <code>$currentUser-&gt;uid</code></li>
  </ol>
  
  <p>So it'll be similar for any other user. Assuming you have a user id (I'll use <code>32</code> for example)</p>
  
  <ol>
  <li>Get user record <code>$userRecord = $this-&gt;_getUserRecordById('32');</code></li>
  <li>Now get user UID <code>$userRecord-&gt;uid</code></li>
  </ol>
  
  <p>my two cents.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-28T13:03:13.997Z
Answers.Text: Its a possible solution but the resulting record is not an element and has no ability to access user custom fields.
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-24T21:03:31.440Z
Answers.LastActivityDate: 2015-09-24T22:34:10.043Z
Answers.LastEditDate: 2015-09-24T22:34:10.043Z
Answers.UserDisplayName: Vadim Goncharov
Body: <p>I want to use the UID to get a user from a url and don't want to use the ID as it is guessable. I know I can do <code>craft()-&gt;users-&gt;getUserByUid($uid);</code> but after getting the uid, the uid is not on the user model which is kinda a pain.</p>
  
  <p>For example what if i wanted the uid for the currently logged in user?</p>
  
Tags: <usermodel>
Title: Getting the UID of a user model
ThreadText: # Getting the UID of a user model
  
  (Asked by: username_0 on 2014-11-26)
  
  I want to use the UID to get a user from a url and don't want to use the ID as it is guessable. I know I can do `craft()->users->getUserByUid($uid);` but after getting the uid, the uid is not on the user model which is kinda a pain.
  
  For example what if i wanted the uid for the currently logged in user?
  
  **Tags:** usermodel
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-11-26. Score: 2 | Accepted answer
  
  Currently, Craft doesn't expose the UID in any of its models.
  
  Kind of a pain, but the only thing I can think of as as a workaround is to write a plugin that has a UserModel with the UID and mimics whatever methods from UsersService that you need.
  
  > **Comments:**
  > **username_0**: thanks username_1, kinda a pain but yeah ill do a workaround.  
  > **username_1**: Entirely possible we expose UID to the UserModel at some point, too. Will have to think about any side-effects from doing so.  
  > **username_0**: i understand security concerns... just as a little background on what I am building: a link in an email that contains the users UID within the link as well as a one time use code to log the user in directly from the email link using userSession->impersonate(). I just wanted to use the UID and Code not the userId and Code -  as the userId is guessable.  
  
  ---
  
  ### Answer by username_2 on 2015-09-24. Score: 2
  
  If you want to get a user model based on UID you can do this.
  
  For current user..
  
  1. Get current user `$currentUser = craft()->userSession->getUser();`
  2. Get user record `$currentUserRecord = $this->_getUserRecordById($currentUser->id);`
  3. Add this private function (copied from UserService.php). This will pull the user record by calling `_getUserRecordById` function
  
     ```
     private function _getUserRecordById($userId)
     {
       $userRecord = UserRecord::model()->findById($userId);
       if (!$userRecord) {
         throw new Exception(Craft::t('No user exists with the ID “{id}”.', array('id' => $userId)));
     }
  
     return $userRecord;
     }
  
     ```
  4. Now get user UID `$currentUser->uid`
  
  So it'll be similar for any other user. Assuming you have a user id (I'll use `32` for example)
  
  1. Get user record `$userRecord = $this->_getUserRecordById('32');`
  2. Now get user UID `$userRecord->uid`
  
  my two cents.
  
  > **Comments:**
  > **username_0**: Its a possible solution but the resulting record is not an element and has no ability to access user custom fields.  
  
  ---
  
  