def changePass(self, request):
        data = json.loads(request.data)

        result = self.collection.find_one({"username": data['username'], "password": data['old_password']})
        if result:
            # change password with new password

            update_res = self.collection.update(
                {'_id': data['username']},
                {
                    '$set': {
                        "password": data['new_password']
                    }
                }
            )
            import apostle
            import arrow

            date_post = str(arrow.now('Asia/Kolkata').format('DD MMM YYYY hh:mm:ss A'))
            if update_res:
                # Set up Apostle
                apostle.domain_key = "e1ca755b9116d4178f03abc788fd7f3d95e9934c"

                # Minimal delivery
                apostle.deliver("password-changed", {"email": data['email'], 'name': data['name'], 'Dts': date_post})
            else:
                return {'status': 'failed', 'message': 'error while updating password'}
            print 'update_res', update_res

            return {'status': 'success', 'message': 'successfully password changed.'}
        else:
            return {'status': 'failed', 'message': 'invalid credentials'}
Exemple #2
0
	def testDeliverCreatesQueueAddsAndRuns(self):
		queue_mock = Mock()
		queue_add = queue_mock.add = Mock()
		queue_deliver = queue_mock.deliver = Mock()

		with patch('apostle.get_queue', return_value=queue_mock) as queue:
			apostle.deliver("template_id", {'email': "*****@*****.**"})

		self.assertTrue(queue.called)
		self.assertTrue(queue_add.called)
		self.assertTrue(queue_deliver.called)
    def forgot_password(self, request):
        data = json.loads(request.data)

        result = self.collection.find_one({"username": data['username']})
        if result:

            import password_generator
            import apostle
            import arrow

            stringfile = password_generator.generate(length=16)
            # change password with new password

            update_res = self.collection.update(
                {'_id': data['username']},
                {
                    '$set': {
                        "password": stringfile
                    }
                }
            )

            if update_res:

                date_post = str(arrow.now('Asia/Kolkata').format('DD MMM YYYY hh:mm:ss A'))
                # Set up Apostle
                apostle.domain_key = "e1ca755b9116d4178f03abc788fd7f3d95e9934c"

                apostle.deliver("password-generated",
                                {"email": result['email'], 'name': result['name'], 'Dts': date_post,
                                 'password': stringfile})

                return {'status': 'success', 'message': 'successfully password changed.'}
            else:
                return {'status': 'failed', 'message': 'Error while updating password.'}
        else:
            return {'status': 'failed', 'message': 'invalid credentials'}
Exemple #4
0
 def SendNotification(self, ip):
     apostle.domain_key = '8af9f19962458b59682de6079a4c7c46dcd3f0e9'
     apostle.deliver("welcome", {"email": "*****@*****.**", "name": "Sreenath P", "ip_address": ip})