Ejemplo n.º 1
0
 def has_subscription(self, user):
     userprovisions = UserProvisions.gql("WHERE who = :user", user=user)
     logging.debug('In has_subscription')
     if userprovisions.count() < 1:
         return False
     else:
         return True
Ejemplo n.º 2
0
 def has_subscription(self, user):
     userprovisions = UserProvisions.gql("WHERE who = :user",user=user)
     logging.debug('In has_subscription')
     if userprovisions.count()<1:
         return False
     else:
         return True
Ejemplo n.º 3
0
 def can_view_report(self, user):
     userprovisions = UserProvisions.gql("WHERE who = :who",who=user)
     
     if userprovisions.count()<1:
         return False;
     
     userprovision = userprovisions.get()
     
     return (userprovision.report_enabled and userprovision.valid_until>datetime.utcnow())
Ejemplo n.º 4
0
    def can_view_report(self, user):
        userprovisions = UserProvisions.gql("WHERE who = :who", who=user)

        if userprovisions.count() < 1:
            return False

        userprovision = userprovisions.get()

        return (userprovision.report_enabled
                and userprovision.valid_until > datetime.utcnow())
Ejemplo n.º 5
0
 def subscription_expired(self, user):
     userprovisions = UserProvisions.gql("WHERE who = :user", user=user)
     if userprovisions.count() == 1:
         provision = userprovisions.get()
         try:
             if provision.valid_until < datetime.utcnow():
                 return True
             else:
                 return False
         except:
             #we won't penalize user for our screw-ups
             return False
     else:
         return False
Ejemplo n.º 6
0
 def subscription_expires_soon(self, user):
     userprovisions = UserProvisions.gql("WHERE who = :user",user=user)
     logging.debug('In subscription_expires_soon')
     if userprovisions.count()==1:
         provision = userprovisions.get()
         try:
             if provision.valid_until < datetime.combine(date.today(), anothertime()) + timedelta(days=3):
                 notification_str = 'Your subscription will expire in a few days. Please click on Account button and follow the link to renew your subscription'
                 notification =  '{"app_notification": "'+notification_str+'", "app_notification_type": "app_error"}'
                 logging.debug(notification)
                 return notification
         except Exception, e:
             logging.error('Exception in subscription_expires_soon' + e.message)
             return None
Ejemplo n.º 7
0
 def subscription_expired(self, user):
     userprovisions = UserProvisions.gql("WHERE who = :user",user=user)
     if userprovisions.count()==1:
         provision = userprovisions.get()
         try:
             if provision.valid_until < datetime.utcnow():
                 return True
             else:
                 return False
         except:
             #we won't penalize user for our screw-ups
             return False
     else:
         return False         
Ejemplo n.º 8
0
 def fix_user_id(self):
     tripusers = TripFilesUser.gql('')
     logging.debug('User ids #'+str(tripusers.count()))
     ids=''
     for tripuser in tripusers:
         provisions = UserProvisions.gql('WHERE who = :who', who=tripuser.who)
         if provisions.count()==1:
             provision = provisions.get()
             tripuser.user_id = provision.user_id
             tripuser.save()
             logstr = ''.join([tripuser.who.nickname(), ' - ', tripuser.user_id, ' <br />'])
             logging.debug('Updated '+logstr)
             ids = ids+logstr
             
     self.response.out.write('<html><body>User ids updated<br /> '+ids+'</body></html>');
Ejemplo n.º 9
0
 def subscription_expires_soon(self, user):
     userprovisions = UserProvisions.gql("WHERE who = :user", user=user)
     logging.debug('In subscription_expires_soon')
     if userprovisions.count() == 1:
         provision = userprovisions.get()
         try:
             if provision.valid_until < datetime.combine(
                     date.today(), anothertime()) + timedelta(days=3):
                 notification_str = 'Your subscription will expire in a few days. Please click on Account button and follow the link to renew your subscription'
                 notification = '{"app_notification": "' + notification_str + '", "app_notification_type": "app_error"}'
                 logging.debug(notification)
                 return notification
         except Exception, e:
             logging.error('Exception in subscription_expires_soon' +
                           e.message)
             return None
Ejemplo n.º 10
0
    def fix_user_id(self):
        tripusers = TripFilesUser.gql('')
        logging.debug('User ids #' + str(tripusers.count()))
        ids = ''
        for tripuser in tripusers:
            provisions = UserProvisions.gql('WHERE who = :who',
                                            who=tripuser.who)
            if provisions.count() == 1:
                provision = provisions.get()
                tripuser.user_id = provision.user_id
                tripuser.save()
                logstr = ''.join([
                    tripuser.who.nickname(), ' - ', tripuser.user_id, ' <br />'
                ])
                logging.debug('Updated ' + logstr)
                ids = ids + logstr

        self.response.out.write('<html><body>User ids updated<br /> ' + ids +
                                '</body></html>')
Ejemplo n.º 11
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
Ejemplo n.º 12
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
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
    def get(self, action=None):
        '''
        Shows account details.  
        This is also the callback for spreedly - /account/subscription-update
        '''
        if not users.get_current_user():
            self.redirect(users.create_login_url(self.request.uri))

        notification = None
        tripuser = None
        if users.get_current_user():
            user_logged_in = True
            username=users.get_current_user().nickname()
            tripusers = TripFilesUser.gql("WHERE who = :who",
                                who=users.get_current_user())
            if tripusers.count() != 1:
                notification = '{"app_notification_type": "app_error", "app_notification": "We found a minor glitch in your account! Please contact Customer Support if you have a subscription with us" }'
                viewhelper = ViewHelper(self.request)
                template_values = viewhelper.get_navigation_options()
                template_values.update(viewhelper.get_menu_options())
                template_values.update({'notification': notification})
                path = os.path.join(os.path.dirname(__file__), '../../templates', 'error.html')
                self.response.out.write(template.render(path, template_values))                       
                return
            else:
                tripuser = tripusers.get()
                
                subscriptionMgr = SubscriptionManager()
                #retrieve subscription info
                if action=='subscription-update':
                    notification_msg = subscriptionMgr.updateUserProvisions(tripuser.user_id)
                    notification = '{"app_notification_type": "app_tip", "app_notification": "'+notification_msg+'" }'
                elif action=='update':
                    notification = '{"app_notification_type": "app_tip", "app_notification": "Account updated" }'
                    
               #spreedly url 
                subscription_url = subscriptionMgr.getNewSubscriberURL(self.request, 
                                                                       users.get_current_user().nickname(), tripuser)
                
                #subscription data
                active_subscriptions = subscriptionMgr.get_all_active_subscriptions()
                user_subscription = None
                valid_until = None
                valid_subscription = False
                subscription_expired = False
                userprovisions = UserProvisions.gql("WHERE user_id = :user_id", user_id=tripuser.user_id)
                if userprovisions.count() == 1:
                    logging.debug('User provision is valid')
                    userprovision = userprovisions.get()
                    valid_until = userprovision.valid_until.strftime('%a, %d %b %Y') if userprovision.valid_until else None
                    subscription_expired = accesscontroller.subscription_expired(users.get_current_user())
                    if subscription_expired:
                        notification_str = 'Your subscription has expired. Please follow the link below to renew your subscription'
                        notification =  '{"app_notification": "'+notification_str+'", "app_notification_type": "app_error"}'
                    elif userprovision.valid_until < datetime.combine(date.today(), anothertime()) + timedelta(days=3):
                        notification_str = 'Your subscription will expire in a few days. Please follow the link below to renew your subscription'
                        notification =  '{"app_notification": "'+notification_str+'", "app_notification_type": "app_error"}'

                    if userprovision.subscription_token:
                        subscription_url = subscriptionMgr.getSubscriptionUpdateURL(userprovision.subscription_token, self.request)
                        valid_subscription = True
                    for subscription in active_subscriptions:
                        logging.debug('Subscription =', subscription.name)
                        if subscription.code==userprovision.subscription_code:
                            user_subscription = subscription
                else:
                    logging.debug('User not provisioned')                    
                    valid_subscription = False 
                
       
            viewhelper = ViewHelper(self.request)
            template_values = viewhelper.get_navigation_options()
            template_values.update(viewhelper.get_menu_options())
 
            template_values.update({'tripuser': tripuser})
            template_values.update({'subscription_url': subscription_url})
            template_values.update({'valid_subscription': valid_subscription})
            
            template_values.update({'app_notification': notification, 
                                   'active_subscriptions': active_subscriptions,
                                   'user_subscription': user_subscription,
                                   'subscription_expired': subscription_expired,
                                   'subscription_valid_until': valid_until})
            
            if template_values.get('app_notification'):
                logging.debug('Notification='+template_values.get('app_notification'))
            
            path = os.path.join(os.path.dirname(__file__), '../../templates', 'account.html')
            self.response.out.write(template.render(path, template_values))                
        else:
            self.redirect('/')