def get(self): user_entity = User(user_name='fg', password='******', email='fgdsb@fgdsb') service = UserService() try: user = yield service.create_with_entity(user_entity) self.write('Added {}'.format(user.uuid)) except EntityAlreadyExistsError: self.write('User name {} exist.'.format(user_entity.user_name))
def post(self): user_name = self.get_body_argument('user_name') password = self.get_body_argument('password') email = self.get_body_argument('email') user = User(user_name=user_name, password=password, email=email) service = UserService() self.set_header('Content-Type', 'application/json') try: user = yield service.create_with_entity(user) self.write({"status": "ok", "uuid": user.uuid}) except EntityAlreadyExistsError: self.write({ "status": "failed", "errorMessage": "User name {} exist.".format(user_name) })