def post(self): data = parser.parse_args() current_user = UserModel.find_by_username(data['username']) if not current_user: return create_response({'message': 'User {} doesn\'t exist' .format(data['username'])}, 404) if UserModel.verify_hash(data['password'], current_user.password): access_token = create_access_token(identity=data['username'], expires_delta=False) return create_response({ 'message': 'Logged in as {}'.format(current_user.username), 'access_token': access_token}, 201) else: return create_response({'message': 'Wrong credentials'}, 401)
def post(self): data = user_parser.parse_args() current_user = UserModel.find_by_username(data['username']) if not current_user: return { 'message': 'User {} doesn\'t exist'.format(data['username']) } if UserModel.verify_hash(data['password'], current_user.password): access_token = create_access_token(identity=data['username']) refresh_token = create_refresh_token(identity=data['username']) return { 'message': 'Logged in as {}'.format(current_user.username), 'access_token': access_token, 'refresh_token': refresh_token } else: return {'message': 'Wrong credentials'}
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)