title: How to have usernames with webapp2's User model?
body: <p>I successfully with webapp2 can authenticate and login/logout users and I have a decorator to know whether a user is logged in and this works:</p>
  
  <pre><code>class MyPageHandler(NewBaseHandler):
      """
      Only accessible to users that are logged in
      """
      @user_required
      def get(self):
          user = self.auth.get_user_by_session()
          self.render_template('mypage.htm', {'user': self.auth.get_user_by_session()})
  </code></pre>
  
  <p>Now I want to add something basic as a username and I suspect that I might not have to subclass the User model provided with webapp2_extras since it is an Expando model. Could you tell me how to add a username or update a user with a username? I didn't try but I believe I can display an auth_id but it's not the same thing as the username?</p>
  
  <p>Thanks</p>
  
  <h2>Update</h2>
  
  <p>It seems as the User model is an expando model you "just add proprties" like this for example when creating a user:</p>
  
  <pre><code>    username = self.request.POST.get('username')
      password = self.request.POST.get('password')
      # Passing password_raw=password so password will be hashed
      # Returns a tuple, where first value is BOOL. If True ok, If False no new user is created
      user = self.auth.store.user_model.create_user(username, password_raw=password)
      user.name = username
  </code></pre>
  
  <p>I didn't thoroughly test the code above but it seems that with webapp2 we won't need to subclass the User class to get the functionality. </p>
  
  <h2>Solution / Workaround</h2>
  
  <pre><code>class SecureRequestHandler(BaseHandler):
      """
          Only accessible to users that are logged in
      """
      @user_required
      def get(self, **kwargs):
          a = self.app.config.get('foo')
          auser = self.auth.get_user_by_session() 
          userid = auser['user_id']
          user = auth_models.User.get_by_id(auser['user_id'])
          try:
              return "Secure zone %s &lt;a href='%s'&gt;Logout&lt;/a&gt;" % (user.name, self.auth_config['logout_url'])
          except (AttributeError, KeyError), e:
              return "Secure zone"
  </code></pre>