Exemplo n.º 1
0
    BaseLoanPersonalInformationView,
    BaseLoanAcceptContractView,
)
from agir.municipales.actions import generate_cost_certificate
from agir.municipales.forms import (
    CommunePageForm,
    MunicipalesLenderForm,
    MunicipalesAskAmountForm,
    ProcurationForm,
    CostCertificateForm,
)
from agir.municipales.models import CommunePage
from agir.municipales.serializers import CommunePageSerializer
from agir.payments.payment_modes import PAYMENT_MODES

send_procurations_bucket_by_ip = TokenBucket("send_procurations_by_ip", 1, 60)
send_procurations_bucket_by_commune = TokenBucket(
    "send_procurations_by_commune", 10, 30)


def certificate_path(commune):
    return f"communes/certificates/{commune.code_departement}-{commune.slug}.pdf"


class CommunePageMixin(View):
    context_object_name = "commune"
    tour = None

    def get_object(self, queryset=None):
        return get_object_or_404(
            self.get_queryset(),
Exemplo n.º 2
0
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Row, Div, Layout
from django import forms
from django.contrib.auth import authenticate

from agir.authentication.tokens import short_code_generator
from agir.lib.token_bucket import TokenBucket
from agir.people.models import Person
from .tasks import send_login_email

send_mail_bucket = TokenBucket("SendMail", 5, 600)
check_short_code_bucket = TokenBucket("CheckShortCode", 5, 180)


class EmailForm(forms.Form):
    messages = {
        "unknown":
        "Cette adresse email ne correspond pas à un signataire.",
        "rate_limited":
        "Vous avez déjà demandé plusieurs emails de connexion. Veuillez laisser quelques minutes pour"
        " vérifier la bonne réception avant d'en demander d'autres.",
    }

    email = forms.EmailField(required=True)

    def __init__(self, has_bookmarked_emails=False, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields[
            "email"].label = f"ou se connecter avec une {'autre ' if has_bookmarked_emails else ''}adresse email"
Exemplo n.º 3
0
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Fieldset, Row, Submit
from django import forms
from django.core.exceptions import ValidationError
from django.core.files import File
from django.core.files.storage import default_storage
from django.utils.translation import ugettext as _

from agir.lib.form_components import *
from agir.lib.form_mixins import MetaFieldsMixin
from agir.lib.token_bucket import TokenBucket
from agir.people.person_forms.field_groups import get_form_part
from .fields import is_actual_model_field, get_data_from_submission, get_form_field
from ..models import Person, PersonFormSubmission

check_person_email_bucket = TokenBucket("PersonFormPersonChoice", 10, 600)


class PersonTagChoiceField(forms.ModelChoiceField):
    def label_from_instance(self, obj):
        return obj.description


class SuperHiddenDisplay(forms.HiddenInput):
    def render(self, name, value, attrs=None, renderer=None):
        return ""


class BasePersonForm(MetaFieldsMixin, forms.ModelForm):
    """base form class for using PersonForm models
from agir.people.models import PersonValidationSMS

from agir.lib.token_bucket import TokenBucket
from agir.people.tasks import send_validation_sms

RATE_LIMITED_1_MINUTE_MESSAGE = _(
    "Vous êtes limités à un SMS toutes les minutes, merci de bien vouloir patienter quelques secondes."
)
RATE_LIMITED_MESSAGE = _(
    "Vous avez déjà demandé plusieurs SMS : merci de bien vouloir patienter jusqu'à réception."
)

logger = logging.getLogger(__name__)

# short terms bucket: make sure maximum 1 SMS is sent every minute
ShortPhoneNumberBucket = TokenBucket("SMSShortPhoneNumber", 1, 60)
ShortPersonBucket = TokenBucket("SMSShortPerson", 1, 60)


def _initialize_buckets():
    global PhoneNumberBucket, PersonBucket, IPBucket
    PhoneNumberBucket = TokenBucket("SMSPhoneNumber", settings.SMS_BUCKET_MAX,
                                    settings.SMS_BUCKET_INTERVAL)
    PersonBucket = TokenBucket("SMSPerson", settings.SMS_BUCKET_MAX,
                               settings.SMS_BUCKET_INTERVAL)
    IPBucket = TokenBucket("SMSIP", settings.SMS_BUCKET_IP_MAX,
                           settings.SMS_BUCKET_IP_INTERVAL)


_initialize_buckets()
Exemplo n.º 5
0
from django.utils.translation import ugettext_lazy as _

from agir.lib.token_bucket import TokenBucket

SubscribeIPBucket = TokenBucket("SubscribeIP", 4, 600)
"""Bucket used to limit subscription by IP

Burst of 4, then 1 every 10 minutes (more than enough for one person,
but we have to keep in mind that IPs can be shared between multiple
persons.
"""

SubscribeEmailBucket = TokenBucket("SubscribeEmail", 3, 1800)
"""Bucket used to limit subscription by email

Burst of 3, then 1 every half an hour (should be more than enough,
as emails should only be subscribed once in theory)
"""

ChangeMailBucket = TokenBucket("ConfirmationChangeMail", 5, 180)
"""Bucket used to limit subscription by email

Burst of 10, then 1 every 3 minutes
"""

MergeAccountBucket = TokenBucket("ConfirmationMergeAccount", 3, 600)
"""Bucket used to limit merge by email

Burst of 3, then 1 every 10 minutes.
"""