Ejemplo n.º 1
0
def process_verify_email_data(input_data):
    if not registration_settings.REGISTER_EMAIL_VERIFICATION_ENABLED:
        raise Http404()
    serializer = VerifyEmailSerializer(data=input_data)
    serializer.is_valid(raise_exception=True)

    data = serializer.validated_data
    signer = RegisterEmailSigner(data)
    verify_signer_or_bad_request(signer)

    email_field = get_user_setting('EMAIL_FIELD')
    user = get_user_by_id(data['user_id'])
    setattr(user, email_field, data['email'])
    user.save()
Ejemplo n.º 2
0
def process_verify_registration_data(input_data):
    if not registration_settings.REGISTER_VERIFICATION_ENABLED:
        raise Http404()
    serializer = VerifyRegistrationSerializer(data=input_data)
    serializer.is_valid(raise_exception=True)

    data = serializer.validated_data
    signer = RegisterSigner(data)
    verify_signer_or_bad_request(signer)

    verification_flag_field = get_user_setting('VERIFICATION_FLAG_FIELD')
    user = get_user_by_id(data['user_id'], require_verified=False)
    setattr(user, verification_flag_field, True)
    user.save()
def process_reset_password_data(input_data):
    serializer = ResetPasswordSerializer(data=input_data)
    serializer.is_valid(raise_exception=True)

    data = serializer.validated_data.copy()
    password = data.pop('password')
    signer = ResetPasswordSigner(data)
    verify_signer_or_bad_request(signer)

    user = get_user_by_id(data['user_id'])
    try:
        validate_password(password, user=user)
    except ValidationError as exc:
        raise serializers.ValidationError(exc.messages[0])
    user.set_password(password)
    user.save()
Ejemplo n.º 4
0
def verify_email(request):
    '''
    Verify email via signature.
    '''
    if not registration_settings.REGISTER_EMAIL_VERIFICATION_ENABLED:
        raise Http404()
    serializer = VerifyEmailSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)

    data = serializer.data
    signer = RegisterEmailSigner(data, request=request)
    verify_signer_or_bad_request(signer)

    email_field = get_user_setting('EMAIL_FIELD')
    user = get_user_by_id(data['user_id'])
    setattr(user, email_field, data['email'])
    user.save()

    return get_ok_response('Email verified successfully')
Ejemplo n.º 5
0
def verify_registration(request):
    '''
    Verify registration via signature.
    '''
    if not registration_settings.REGISTER_VERIFICATION_ENABLED:
        raise Http404()
    serializer = VerifyRegistrationSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)

    data = serializer.data
    signer = RegisterSigner(data, request=request)
    verify_signer_or_bad_request(signer)

    verification_flag_field = get_user_setting('VERIFICATION_FLAG_FIELD')
    user = get_user_by_id(data['user_id'], require_verified=False)
    setattr(user, verification_flag_field, True)
    user.save()

    return get_ok_response('User verified successfully')
Ejemplo n.º 6
0
def reset_password(request):
    '''
    Reset password, given the signature and timestamp from the link.
    '''
    serializer = ResetPasswordSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)

    data = serializer.data.copy()
    password = data.pop('password')
    signer = ResetPasswordSigner(data, request=request)
    verify_signer_or_bad_request(signer)

    user = get_user_by_id(data['user_id'])
    try:
        validate_password(password, user=user)
    except ValidationError as exc:
        raise serializers.ValidationError(exc.messages[0])
    user.set_password(password)
    user.save()

    return get_ok_response('Reset password successful')