old_contents: # coding: utf-8
  
  import uuid, datetime
  
  from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
  from sqlalchemy.orm.state import InstanceState
  
  from apps import BaseRequestHandler
  from apps.models import User, Loud
  from utils.decorator import authenticated
  
  class UserHandler(BaseRequestHandler):
  
      @authenticated
      def get(self, phn):
          user = User.query.get_by_phone(phn)
  
          if user:
              info = user.user_to_dict(self.current_user)
          else:
              info = None
  
          self.render_json(info)
  
      def post(self, phn):
          user = User()
          data = self.get_data()
          user.from_dict(data)
  
          self.render_json(user.save() and Success or Fail)
  
      @authenticated
      def put(self, phn):
          ''' The User object can't modify phone
          '''
          user = self.current_user
  
          data = self.get_data()
          user.from_dict(data)
  
          self.render_json(user.save() and Success or Fail)
  
      @authenticated
      def delete(self, phn):
          user = self.current_user
          
          self.db.delete(user) # PS: delete all relation data
          # delete user data 
          self.render_json(Success)
  
  
  class AuthHandler(BaseRequestHandler):
  
      def post(self):
          if not self.is_available_client():
              self.render_error(401)
              return
          else:
              info = self.get_data()
              if 'phone' in info and 'password' in info:
                  user = User.query.get_by_phone(info['phone'])
                  if user and user.authenticate(info['password']):
                      user.token = uuid.uuid5(uuid.NAMESPACE_URL, "%s%s" % (user.phone,
                          datetime.datetime.now()))
                      user.save()
                      info = user.user_to_dict_by_auth()
                  else:
                      info = Fail
              else:
                  info = Fail
          self.render_json(info) 
  
new_contents: # coding: utf-8
  
  import uuid, datetime
  
  from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
  from sqlalchemy.orm.state import InstanceState
  
  from apps import BaseRequestHandler
  from apps.models import User, Loud
  from utils.decorator import authenticated
  from utils.constants import Fail, Success
  
  class UserHandler(BaseRequestHandler):
  
      @authenticated
      def get(self, phn):
          user = User.query.get_by_phone(phn)
  
          if user:
              info = user.user_to_dict(self.current_user)
          else:
              info = None
  
          self.render_json(info)
  
      def post(self, phn):
          user = User()
          data = self.get_data()
          user.from_dict(data)
  
          self.render_json(user.save() and Success or Fail)
  
      @authenticated
      def put(self, phn):
          ''' The User object can't modify phone
          '''
          user = self.current_user
  
          data = self.get_data()
          user.from_dict(data)
  
          self.render_json(user.save() and Success or Fail)
  
      @authenticated
      def delete(self, phn):
          user = self.current_user
          
          self.db.delete(user) # PS: delete all relation data
          # delete user data 
          self.render_json(Success)
  
  
  class AuthHandler(BaseRequestHandler):
  
      def post(self):
          if not self.is_available_client():
              self.render_error(401)
              return
          else:
              info = self.get_data()
              if 'phone' in info and 'password' in info:
                  user = User.query.get_by_phone(info['phone'])
                  if user and user.authenticate(info['password']):
                      user.token = uuid.uuid5(uuid.NAMESPACE_URL, "%s%s" % (user.phone,
                          datetime.datetime.now()))
                      user.save()
                      info = user.user_to_dict_by_auth()
                  else:
                      info = Fail
              else:
                  info = Fail
          self.render_json(info) 
  
subject: fix bug