<commit_before>from flask import Response

from radar.auth.forgot_password import UserNotFound, reset_password, InvalidToken
from radar.serializers.core import Serializer
from radar.serializers.fields import StringField
from radar.validation.core import ValidationError
from radar.validation.reset_password import ResetPasswordValidation
from radar.views.core import ApiView, request_json


class ResetPasswordSerializer(Serializer):
    token = StringField()
    username = StringField()
    password = StringField()


class ResetPasswordView(ApiView):
    @request_json(ResetPasswordSerializer, ResetPasswordValidation)
    def post(self, data):
        token = data['token']
        username = data['username']
        password = data['password']

        try:
            reset_password(token, username, password)
        except InvalidToken:
            raise ValidationError({'token': 'Your token has expired, please try again.'})
        except UserNotFound:
            raise ValidationError({'username': 'No user found with that username.'})

        return Response(status=200)


def register_views(app):
    app.add_public_endpoint('reset_password')
    app.add_url_rule('/reset-password', view_func=ResetPasswordView.as_view('reset_password'))
<commit_msg>Remove stray newline<commit_after>from flask import Response

from radar.auth.forgot_password import UserNotFound, reset_password, InvalidToken
from radar.serializers.core import Serializer
from radar.serializers.fields import StringField
from radar.validation.core import ValidationError
from radar.validation.reset_password import ResetPasswordValidation
from radar.views.core import ApiView, request_json


class ResetPasswordSerializer(Serializer):
    token = StringField()
    username = StringField()
    password = StringField()


class ResetPasswordView(ApiView):
    @request_json(ResetPasswordSerializer, ResetPasswordValidation)
    def post(self, data):
        token = data['token']
        username = data['username']
        password = data['password']

        try:
            reset_password(token, username, password)
        except InvalidToken:
            raise ValidationError({'token': 'Your token has expired, please try again.'})
        except UserNotFound:
            raise ValidationError({'username': 'No user found with that username.'})

        return Response(status=200)


def register_views(app):
    app.add_public_endpoint('reset_password')
    app.add_url_rule('/reset-password', view_func=ResetPasswordView.as_view('reset_password'))
{'fraction_non_alphanumeric': 0.08575924468922108, 'fraction_numerical': 0.0023603461841070024, 'mean_word_length': 4.320083682008368, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2216551', 'n_tokens_mistral': 646, 'n_tokens_neox': 622, 'n_words': 170}