Exemplo n.º 1
0
    def updateUserProvisions(self, subscriber_id):
        userprovisions = UserProvisions.gql("WHERE user_id = :user_id",
                                            user_id=subscriber_id)
        if userprovisions.count() != 1:
            logging.error(
                'User not provisioned but has created subscription?! Provisioning now...'
            )
            userprovision = UserProvisions()
            userprovision.user_id = subscriber_id
            userprovision.who = users.get_current_user()
            userprovision.save_enabled = True
            userprovision.report_enabled = True
            userprovision.provisioned_for = ['WEB']
            #default 15 days validity
            userprovision.valid_until = datetime.combine(
                date.today(), anothertime()) + timedelta(days=15)
            #return False, '', 'Could not update subscription data. Please contact customer support.'
        else:
            userprovision = userprovisions.get()

        subscription_valid = True
        subscription_valid_until = userprovision.valid_until

        subscriber_details = spreedlyinterface.subscriber_details(
            subscriber_id)
        logging.debug('Fetched Subscriber details %s' %
                      str(subscriber_details))

        if subscriber_details and subscriber_details[
                'customer-id'] == subscriber_id:
            logging.debug('updating tripfiles userprovisions...')
            valid_until_str = subscriber_details[
                'active-until'] if subscriber_details.has_key(
                    'active-until') else None
            if valid_until_str:
                valid_until = datetime.strptime(
                    valid_until_str,
                    '%Y-%m-%dT%H:%M:%SZ')  #u'2010-11-22T16:45:13Z',
                userprovision.valid_until = valid_until

            subscription_valid = True if subscriber_details.has_key(
                'active') and subscriber_details['active'] == 'true' else False
            notification_msg = 'Subscription active' if subscription_valid else 'Subscription inactive'
            userprovision.save_enabled = subscription_valid
            userprovision.report_enabled = subscription_valid
            userprovision.subscription_token = subscriber_details[
                'token'] if subscriber_details.has_key('token') else None
            userprovision.subscription_code = subscriber_details[
                'feature-level'] if subscriber_details.has_key(
                    'feature-level') else None
            userprovision.save()

        return notification_msg
Exemplo n.º 2
0
    def updateUserProvisions(self, subscriber_id):
        userprovisions = UserProvisions.gql("WHERE user_id = :user_id",user_id=subscriber_id)
        if userprovisions.count()!=1:
            logging.error('User not provisioned but has created subscription?! Provisioning now...')
            userprovision = UserProvisions()            
            userprovision.user_id = subscriber_id
            userprovision.who = users.get_current_user()
            userprovision.save_enabled = True
            userprovision.report_enabled = True
            userprovision.provisioned_for = ['WEB']
            #default 15 days validity
            userprovision.valid_until = datetime.combine(date.today(), anothertime()) + timedelta(days=15)
            #return False, '', 'Could not update subscription data. Please contact customer support.'
        else:
            userprovision = userprovisions.get()
            
        subscription_valid=True
        subscription_valid_until=userprovision.valid_until 
        
        subscriber_details = spreedlyinterface.subscriber_details(subscriber_id)
        logging.debug('Fetched Subscriber details %s' % str(subscriber_details))
  
        if subscriber_details and subscriber_details['customer-id']==subscriber_id:
            logging.debug('updating tripfiles userprovisions...')                    
            valid_until_str = subscriber_details['active-until'] if subscriber_details.has_key('active-until') else None
            if valid_until_str:
                valid_until = datetime.strptime(valid_until_str,  '%Y-%m-%dT%H:%M:%SZ') #u'2010-11-22T16:45:13Z', 
                userprovision.valid_until = valid_until

            subscription_valid = True if subscriber_details.has_key('active') and subscriber_details['active']=='true' else False
            notification_msg = 'Subscription active'  if subscription_valid else 'Subscription inactive'
            userprovision.save_enabled = subscription_valid
            userprovision.report_enabled = subscription_valid
            userprovision.subscription_token = subscriber_details['token'] if subscriber_details.has_key('token') else None
            userprovision.subscription_code = subscriber_details['feature-level'] if subscriber_details.has_key('feature-level') else None
            userprovision.save()

            
        return notification_msg
Exemplo n.º 3
0
    def post(self):     
        if not users.get_current_user():
            self.redirect('/')

        logging.debug('In register->post')
        first_name = middle_name = last_name = ' '
        work_title = home_address = office_base_address = ''
        work_id = work_department = ''
        vehicle_make = vehicle_cc = vehicle_registration = ''
        
        #if self.request.get('input_first_name'):
        first_name = self.request.get('input_first_name')
        #if self.request.get('input_middle_name'):
        middle_name = self.request.get('input_middle_name')
        #if self.request.get('input_last_name'):
        last_name = self.request.get('input_last_name')
            
        #if self.request.get('input_work_title'):
        work_title = self.request.get('input_work_title')
        #if self.request.get('input_work_id'):
        work_id = self.request.get('input_work_id')
        #if self.request.get('input_work_department'):
        work_department = self.request.get('input_work_department')
            
            
        #if self.request.get('input_mileage_template'):
        mileage_template = self.request.get('input_mileage_template')
            
            
        #if self.request.get('input_home_address'):
        home_address = self.request.get('input_home_address')
        #if self.request.get('input_office_base_address'):
        office_base_address = self.request.get('input_office_base_address')
        #if self.request.get('input_vehicle_make'):
        vehicle_make = self.request.get('input_vehicle_make')
        #if self.request.get('input_vehicle_cc'):
        vehicle_cc = self.request.get('input_vehicle_cc')
            
        #if self.request.get('input_vehicle_registration'):
        vehicle_registration = self.request.get('input_vehicle_registration')
        
       
        
        if users.get_current_user():
            #account registration
            tripuser = TripFilesUser()
            tripuser.who = users.get_current_user()
            tripuser.first_name = first_name
            tripuser.middle_name = middle_name
            tripuser.last_name = last_name
            tripuser.email = users.get_current_user().email()
            tripuser.work_title = work_title
            tripuser.work_id = work_id
            tripuser.work_department = work_department
            
            tripuser.mileage_template = mileage_template
            tripuser.home_address = home_address
            tripuser.office_base_address = office_base_address
            tripuser.vehicle_make = vehicle_make
            tripuser.vehicle_cc = vehicle_cc            
            tripuser.vehicle_registration = vehicle_registration

            userprovision = UserProvisions()            
            userprovision.user_id = uuid.uuid4().hex
            userprovision.who = users.get_current_user()
            userprovision.save_enabled = False
            userprovision.report_enabled = False
            userprovision.provisioned_for = ['WEB']
            #15 days validity
            userprovision.valid_until = datetime.combine(date.today(), anothertime()) + timedelta(days=15)
            
            tripuser.user_id = userprovision.user_id
            tripuser.save()
            userprovision.save()
            
            notifications = first_name+' '+last_name+ ', your details are now registered.'
        else:
            self.redirect('/')
            
        #spreedly url 
        subscriptionMgr = SubscriptionManager()
        subscription_url = subscriptionMgr.getNewSubscriberURL(self.request, 
                                                               users.get_current_user().nickname(), tripuser)
        logging.debug('Subs url: '+ subscription_url)
        self.redirect(subscription_url)