Пример #1
0
    def validate(self, data):
        confirm = ConfirmationCode.objects.filter(
            phone=integers_only(data['phone']),
            code=data['code'],
            is_used=False
        ).first()

        if not confirm:
            raise ValidationError({'code': _("Неверный код подтверждения")})

        data['phone'] = integers_only(data['phone'])
        data['confirm'] = confirm
        return data
Пример #2
0
 def verify(self, phone, code):
     query = self.order_by('-id')
     query = query.filter(user__phone=integers_only(phone))
     query = query.filter(code=code)
     query = query.filter(expires_at__gte=timezone.now())
     query = query.filter(is_used=False)
     return query.first()
Пример #3
0
    def sign_in(self, phone):
        from users.models import ConfirmationCode

        phone = integers_only(phone)
        user, created = self.get_or_create(phone=phone,
                                           defaults={
                                               'username': phone,
                                               'password': ''
                                           })

        confirmation = ConfirmationCode.objects.create(
            user=user, phone=phone, type=ConfirmationCode.AUTHENTICATION)
        confirmation.send()
        return user, confirmation.code
Пример #4
0
    def validate(self, data):
        phone = integers_only(data.get('phone'))

        user = User.objects.filter(phone=phone).first()

        if user:
            if not user.is_active:
                raise ValidationError({'user': _("Пользователь не активен")})

            confirmation = ConfirmationCode.objects.filter(user=user).last()
            if confirmation and confirmation.created_at + timedelta(
                    minutes=1) >= timezone.now():
                raise ValidationError({
                    'user':
                    _("Повторная отправка SMS возможна через 60 секунд")
                })

        return data
Пример #5
0
    def validate(self, data):
        if User.objects.filter(phone=integers_only(data['phone'])).exists():
            raise ValidationError({'phone': _("Пользователь с таким номером уже существует.")})
        data['phone'] = integers_only(data['phone'])

        return data