Esempio n. 1
0
	def notify_all_source_delete(self, source, originating_device_id):
		devices = UserDevices.get_user_devices(source.owner)
		for device in devices:
			# Skip the device if that was the device that originated the request.
			if device.key().id() == originating_device_id:
				continue
			self.notify_source_delete(source, device)
Esempio n. 2
0
 def notify_all_source_delete(self, source, originating_device_id):
     devices = UserDevices.get_user_devices(source.owner)
     for device in devices:
         # Skip the device if that was the device that originated the request.
         if device.key().id() == originating_device_id:
             continue
         self.notify_source_delete(source, device)
Esempio n. 3
0
    def send_to_all(self, message):
        devices = UserDevices.get_user_devices(message.owner)

        for device in devices:
            self.send(message, device)

        message.deliveredToGoogle = True
        message.lastDeliveryAttempt = datetime.datetime.now()
        message.put()
Esempio n. 4
0
	def GET(self):
		devices = UserDevices.all()

		result = ""

		for device in devices:
			result += device.owner.email() + '\n'

		return result
Esempio n. 5
0
	def send_to_all(self, message):
		devices = UserDevices.get_user_devices(message.owner)

		for device in devices:
			self.send(message, device)

		message.deliveredToGoogle = True
		message.lastDeliveryAttempt = datetime.datetime.now()
		message.put()
Esempio n. 6
0
    def GET(self):
        devices = UserDevices.all()

        result = ""

        for device in devices:
            result += device.owner.email() + '\n'

        return result
Esempio n. 7
0
	def GET(self):
		# Must be logged in.
		login_required()

		# List all their sources.
		sources = UserSources.get_user_sources(users.get_current_user())
		sources = sorted(sources, key=lambda source: source.title)
		renderer.addDataList('sources', sources)

		# List all their devices.
		devices = UserDevices.get_user_devices(users.get_current_user())
		devices = sorted(devices, key=lambda device: device.updated)
		renderer.addDataList('devices', devices)

		return renderer.render('profile/index.html')
Esempio n. 8
0
    def GET(self):
        # Must be logged in.
        login_required()

        # List all their sources.
        sources = UserSources.get_user_sources(users.get_current_user())
        sources = sorted(sources, key=lambda source: source.title)
        renderer.addDataList('sources', sources)

        # List all their devices.
        devices = UserDevices.get_user_devices(users.get_current_user())
        devices = sorted(devices, key=lambda device: device.updated)
        renderer.addDataList('devices', devices)

        return renderer.render('profile/index.html')
Esempio n. 9
0
	def get_device(self):
		# If ID supplied, find and update that ID.
		input = web.input(id = None)

		devices = UserDevices.get_user_device_collection(users.get_current_user())
		device = UserDevice(parent=devices)
		if input.id and long(input.id) > 0:
			# Load device from ID.
			device = UserDevice.get_by_id(long(input.id), devices)

			if not device:
				# Invalid ID. 404.
				raise web.notfound()

			# Check that the device belongs to the logged in user.
			if device.owner.user_id() != users.get_current_user().user_id():
				# It's not theirs. 404.
				# TODO: Test this more and better.
				raise web.notfound()

		return device
Esempio n. 10
0
    def get_device(self):
        # If ID supplied, find and update that ID.
        input = web.input(id=None)

        devices = UserDevices.get_user_device_collection(
            users.get_current_user())
        device = UserDevice(parent=devices)
        if input.id and long(input.id) > 0:
            # Load device from ID.
            device = UserDevice.get_by_id(long(input.id), devices)

            if not device:
                # Invalid ID. 404.
                raise web.notfound()

            # Check that the device belongs to the logged in user.
            if device.owner.user_id() != users.get_current_user().user_id():
                # It's not theirs. 404.
                # TODO: Test this more and better.
                raise web.notfound()

        return device
Esempio n. 11
0
	def GET(self):
		# Must be logged in.
		login_required()
		mailbody = "Newtifry user data : \n"
		mailbody += "User : "******"\n"
		mailbody += "Message count : " + str(get_message_count(users.get_current_user())) + "\n"
		mailbody += "Sources : \n"
		# List all their sources.
		sources = UserSources.get_user_sources(users.get_current_user())
		sources = sorted(sources, key=lambda source: source.title)
		for source in sources:
			mailbody += source.title + " "
			if source.enabled:
				mailbody += "Enabled " 
			else:
				mailbody += "Disabled "
			mailbody += source.externalKey + "\n"
		mailbody += "\nDevices : \n"

		devices = UserDevices.get_user_devices(users.get_current_user())
		devices = sorted(devices, key=lambda device: device.updated)
		for device in devices:
			mailbody += device.deviceNickname + "\n\tHash : " + device.hash() + "\n\tDevicekey " + device.deviceKey + "\n\tDevice Version " + device.deviceVersion + "\n"
		
		mailbody += "\n\nRegards\n"
		
#		renderer.addDataList('sources', sources)
#		renderer.addData('messagecount', get_message_count(users.get_current_user()));
#		renderer.addData('messageleft', get_quota(users.get_current_user()));

		# List all their devices.
#		renderer.addDataList('devices', devices)
		mail.send_mail(sender="Newtifry <*****@*****.**>", to="Newtifry user " + users.get_current_user().email(), subject="Newtifry user data", body=mailbody)

		renderer.addData('owner_mail', users.get_current_user().email())
		return renderer.render('profile/datasent.html')
Esempio n. 12
0
 def transaction(device):
     devices = UserDevices.get_user_device_collection_static(
         users.get_current_user())
     device.put()
     devices.add_device(device)
     devices.put()
Esempio n. 13
0
 def transaction(device):
     devices = UserDevices.get_user_device_collection_static(
         users.get_current_user())
     devices.remove_device(device)
     device.delete()
     devices.put()
Esempio n. 14
0
    def POST(self, action):
        # You must be logged in.
        login_required()

        if action == 'delete':
            device = self.get_device()

            # Let the device know it's been deleted.
            ac2dm = AC2DM.factory()
            ac2dm.notify_device_delete(device)

            devices = UserDevices.get_user_device_collection(
                users.get_current_user())

            # Now delete it.
            def transaction(device):
                devices = UserDevices.get_user_device_collection_static(
                    users.get_current_user())
                devices.remove_device(device)
                device.delete()
                devices.put()

            db.run_in_transaction(transaction, device)

            renderer.addData('success', True)
            return renderer.render('device/deletecomplete.html')
        elif action == 'deregister':
            device = self.get_device()
            devices = UserDevices.get_user_device_collection(
                users.get_current_user())

            def transaction(device):
                devices = UserDevices.get_user_device_collection_static(
                    users.get_current_user())
                devices.remove_device(device)
                device.delete()
                devices.put()

            db.run_in_transaction(transaction, device)
            renderer.addData('success', True)
            return renderer.render('apionly.html')
        elif action == 'register':
            # And we need the following variables.
            # The defaults are provided below.
            input = web.input(devicekey=None,
                              devicetype=None,
                              deviceversion=None,
                              nickname=None)

            # We must have the following keys passed,
            # otherwise this is an invalid request.
            if not input.devicekey and not input.devicetype:
                # Fail with an error.
                renderer.addData(
                    'error',
                    'Missing required parameters "devicekey" and "devicetype".'
                )
                return renderer.render('apionly.html')

            # Check 'devicetype' is 'android' - nothing else is supported right now.
            if input.devicetype != 'android':
                renderer.addData(
                    'error',
                    'Only Android devices are supported at the moment, sorry.')
                return renderer.render('apionly.html')

            # Get the users's device collection.
            devices = UserDevices.get_user_device_collection(
                users.get_current_user())

            # If ID supplied, find and update that ID.
            device = self.get_device()

            # Is it a new device? Double check that the key isn't already
            # attached to another record (with the same owner!)
            if not device.dict().has_key('id'):
                # Attempt to find another device with the same key.
                for existingDevice in devices.get_devices():
                    if existingDevice.deviceKey == input.devicekey:
                        # Found one - update that object instead.
                        device = existingDevice

            device.updated = datetime.datetime.now()
            device.owner = users.get_current_user()
            device.deviceKey = input.devicekey
            device.deviceType = input.devicetype
            device.deviceVersion = input.deviceversion
            device.deviceNickname = input.nickname

            def transaction(device):
                devices = UserDevices.get_user_device_collection_static(
                    users.get_current_user())
                device.put()
                devices.add_device(device)
                devices.put()

            db.run_in_transaction(transaction, device)

            renderer.addData('device', device)
            return renderer.render('apionly.html')
Esempio n. 15
0
			def transaction(device):
				devices = UserDevices.get_user_device_collection_static(users.get_current_user())
				device.put()
				devices.add_device(device)
				devices.put()
Esempio n. 16
0
			def transaction(device):
				devices = UserDevices.get_user_device_collection_static(users.get_current_user())
				devices.remove_device(device)
				device.delete()
				devices.put()
Esempio n. 17
0
	def POST(self, action):
		# You must be logged in.
		login_required()

		if action == 'delete':
			device = self.get_device()

			# Let the device know it's been deleted.
			ac2dm = AC2DM.factory()
			ac2dm.notify_device_delete(device)

			devices = UserDevices.get_user_device_collection(users.get_current_user())

			# Now delete it.
			def transaction(device):
				devices = UserDevices.get_user_device_collection_static(users.get_current_user())
				devices.remove_device(device)
				device.delete()
				devices.put()
			db.run_in_transaction(transaction, device)
	
			renderer.addData('success', True)
			return renderer.render('device/deletecomplete.html')
		elif action == 'deregister':
			device = self.get_device()
			devices = UserDevices.get_user_device_collection(users.get_current_user())

			def transaction(device):
				devices = UserDevices.get_user_device_collection_static(users.get_current_user())
				devices.remove_device(device)
				device.delete()
				devices.put()
			db.run_in_transaction(transaction, device)
			renderer.addData('success', True)
			return renderer.render('apionly.html')
		elif action == 'register':
			# And we need the following variables.
			# The defaults are provided below.
			input = web.input(devicekey = None, devicetype = None, deviceversion = None, nickname = None)

			# We must have the following keys passed,
			# otherwise this is an invalid request.
			if not input.devicekey and not input.devicetype:
				# Fail with an error.
				renderer.addData('error', 'Missing required parameters "devicekey" and "devicetype".')
				return renderer.render('apionly.html')

			# Check 'devicetype' is 'android' - nothing else is supported right now.
			if input.devicetype != 'android':
				renderer.addData('error', 'Only Android devices are supported at the moment, sorry.')
				return renderer.render('apionly.html')

			# Get the users's device collection.
			devices = UserDevices.get_user_device_collection(users.get_current_user())

			# If ID supplied, find and update that ID.
			device = self.get_device()

			# Is it a new device? Double check that the key isn't already
			# attached to another record (with the same owner!)
			if not device.dict().has_key('id'):
				# Attempt to find another device with the same key.
				for existingDevice in devices.get_devices():
					if existingDevice.deviceKey == input.devicekey:
						# Found one - update that object instead.
						device = existingDevice

			device.updated = datetime.datetime.now()
			device.owner = users.get_current_user()
			device.deviceKey = input.devicekey
			device.deviceType = input.devicetype
			device.deviceVersion = input.deviceversion
			device.deviceNickname = input.nickname

			def transaction(device):
				devices = UserDevices.get_user_device_collection_static(users.get_current_user())
				device.put()
				devices.add_device(device)
				devices.put()
			db.run_in_transaction(transaction, device)
			
			renderer.addData('device', device)
			return renderer.render('apionly.html')