コード例 #1
0
ファイル: api_v1.py プロジェクト: xenops/badgr-server
    def get(self, request, id, **kwargs):
        email_address = self.get_email(pk=id)
        if email_address is None or email_address.user_id != self.request.user.id:
            return Response(status=status.HTTP_404_NOT_FOUND)

        serializer = EmailSerializerV1(email_address, context={'request': request})
        return Response(serializer.data)
コード例 #2
0
ファイル: api_v1.py プロジェクト: xenops/badgr-server
    def post(self, request, **kwargs):
        serializer = EmailSerializerV1(data=request.data, context={'request': request})
        serializer.is_valid(raise_exception=True)

        email_address = serializer.save(user=request.user)
        email = serializer.data
        email_address.send_confirmation(request)
        return Response(email, status=status.HTTP_201_CREATED)
コード例 #3
0
 def post(self, request, **kwargs):
     serializer = EmailSerializerV1(data=request.data, context={'request': request})
     serializer.is_valid(raise_exception=True)
     try: # check if email already exists
         CachedEmailAddress.objects.get(email = request.data.get('email'))
         return Response({'error': "Could not register email address. Address already in use."}, status=status.HTTP_400_BAD_REQUEST)
     except CachedEmailAddress.DoesNotExist:
         pass 
     email_address = serializer.save(user=request.user)
     email = serializer.data
     email_address.send_confirmation(request)
     return Response(email, status=status.HTTP_201_CREATED)
コード例 #4
0
ファイル: api_v1.py プロジェクト: jeborsel/badgr-server
    def put(self, request, id, **kwargs):
        email_address = self.get_email(pk=id)
        if email_address is None:
            return Response(status=status.HTTP_404_NOT_FOUND)
        if email_address.user_id != request.user.id:
            return Response(status=status.HTTP_403_FORBIDDEN)

        if email_address.verified:
            if request.data.get('primary'):
                email_address.set_as_primary()
                email_address.publish()
        else:
            if request.data.get('resend'):
                send_confirmation = False
                current_time = datetime.datetime.now()
                last_request_time = email_address.get_last_verification_sent_time(
                )

                if last_request_time is None:
                    email_address.set_last_verification_sent_time(
                        datetime.datetime.now())
                    send_confirmation = True
                else:
                    time_delta = current_time - last_request_time
                    if time_delta > RATE_LIMIT_DELTA:
                        send_confirmation = True

                if send_confirmation:
                    email_address.send_confirmation(request=request)
                    email_address.set_last_verification_sent_time(
                        datetime.datetime.now())
                else:
                    remaining_time_obj = RATE_LIMIT_DELTA - (
                        datetime.datetime.now() - last_request_time)
                    remaining_min = (remaining_time_obj.seconds // 60) % 60
                    remaining_sec = remaining_time_obj.seconds % 60
                    remaining_time_rep = "{} minutes and {} seconds".format(
                        remaining_min, remaining_sec)

                    return Response(
                        "Will be able to re-send verification email in %s." %
                        (str(remaining_time_rep)),
                        status=status.HTTP_429_TOO_MANY_REQUESTS)

        serializer = EmailSerializerV1(email_address,
                                       context={'request': request})
        serialized = serializer.data
        return Response(serialized, status=status.HTTP_200_OK)
コード例 #5
0
ファイル: api_v1.py プロジェクト: stackroute/badgr-server
    def put(self, request, id, **kwargs):
        email_address = self.get_email(pk=id)
        if email_address is None:
            return Response(status=status.HTTP_404_NOT_FOUND)
        if email_address.user_id != request.user.id:
            return Response(status=status.HTTP_403_FORBIDDEN)

        if email_address.verified:
            if request.data.get('primary'):
                email_address.set_as_primary()
                email_address.publish()
        else:
            if request.data.get('resend'):
                email_address.send_confirmation(request=request)

        serializer = EmailSerializerV1(email_address,
                                       context={'request': request})
        serialized = serializer.data
        return Response(serialized, status=status.HTTP_200_OK)
コード例 #6
0
ファイル: api_v1.py プロジェクト: jeborsel/badgr-server
 def get(self, request, **kwargs):
     instances = request.user.cached_emails()
     serializer = EmailSerializerV1(instances,
                                    many=True,
                                    context={'request': request})
     return Response(serializer.data)