コード例 #1
0
ファイル: api.py プロジェクト: alainwolf/openbroadcast.org
    def __forget_device(self, request, **kwargs):
        """
        'forgetting' a device happens if a user unlinks a 'hardware' device from daysyView

        what happens:
         - a new device with a 'virtual' serial-number is created and attached to the user/profile
         - data (files) form the old device are copied to the new one
         - old device and its data (files) are deleted.
        """
        self.method_check(request, allowed=['get', ])
        self.throttle_check(request)
        self.is_authenticated(request)


        user = User.objects.get(**self.remove_api_resource_names(kwargs))

        log.info('forget device for %s' % user.email)

        old_device = user.profile.device

        device = Device()
        device.generate_serial_number(user.pk)
        from django.core.files.base import ContentFile
        # temporary store data
        try:
            data_file = ContentFile(old_device.data_file.read())
        except Exception, e:
            data_file = None
            print e
コード例 #2
0
ファイル: api.py プロジェクト: alainwolf/openbroadcast.org
        # separate flag in profile model to track email confirmation
        user = create_user(data['email'], data['password'], is_active=True)

        # hook up with registration
        registration_profile = RegistrationProfile.objects.create_profile(user)
        registration_signals.user_registered.send(sender=self.__class__, user=user, request=request)
        send_activation_email(registration_profile)

        # create device for user
        if serial_number:
            # device, created = Device.objects.get_or_create(profiles__in=[user.pk, ], serial_number=serial_number)
            device, created = Device.objects.get_or_create(serial_number=serial_number, status=2)
        else:
            # no serial provided, so create a 'app' device and generate a serial for it
            device = Device()
            device.generate_serial_number(user.pk)
            device.status = 2
            device.save()

        # finally create the user profile
        profile, created = UserProfile.objects.get_or_create(user=user, device=device)

        log.info('registraion success: %s - serial number: %s' % (email, device.serial_number))

        bundle = self.build_bundle(obj=user, request=request)
        bundle = self.full_dehydrate(bundle)

        # provide api key
        bundle.data['api_key'] = bundle.obj.api_key.key

        self.log_throttled_access(request)