def post(self): parser = reqparse.RequestParser() parser.add_argument('username', help='This field cannot be blank', required=True) parser.add_argument('password', help='This field cannot be blank', required=True) data = 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 put(self): parser = reqparse.RequestParser() parser.add_argument('password', help='This field cannot be blank', required=True) parser.add_argument("newpassword", help='This argument cannot be blank', required=True) username = get_jwt_identity() current_user = UserModel.find_by_username(username) data = parser.parse_args() if UserModel.verify_hash(data['password'], current_user.password): current_user.password = UserModel.generate_hash( data['newpassword']) current_user.add_commit_data() return {'message': 'Your password was updated successfully!'} else: return {"message": 'Wrong password'}