def post(self): data = user_parser.parse_args() if UserModel.find_by_username(data['username']): return { 'message': 'User {} already exists'.format(data['username']) } new_user = UserModel(username=data['username'], password=UserModel.generate_hash( data['password'])) try: new_user.save_to_db() access_token = create_access_token(identity=data['username']) refresh_token = create_refresh_token(identity=data['username']) return { 'message': 'User {} was created'.format(data['username']), 'access_token': access_token, 'refresh_token': refresh_token } except: return {'message': 'Something went wrong'}, 500
def post(self): data = parser.parse_args() if UserModel.find_by_username(data['username']): return create_response({'message': 'User {} already exists' .format(data['username'])}, 409) new_user = UserModel( username=data['username'], password=UserModel.generate_hash(data['password']) ) try: new_user.save_to_db() access_token = create_access_token(identity=data['username'], expires_delta=False) return create_response({ 'message': 'User {} was created'.format(data['username']), 'access_token': access_token }, 201) except Exception: return create_response({'message': 'Something went wrong'}, 500)