Ejemplo n.º 1
0
    def get(self):
        logging.debug('In register->get')
        username = None
        user_logged_in = False
        user_registered = False
        notification = None
        url = users.create_login_url(self.request.uri)
        if users.get_current_user():
            url = users.create_logout_url('/')	
            user_logged_in = True
            username=users.get_current_user().nickname()
            tripuser = TripFilesUser.gql("WHERE who = :who",
                                who=users.get_current_user())
            if tripuser.count() > 0:
                self.redirect('/account/update')
        else:
            self.redirect(users.create_login_url(self.request.uri))
            
        viewhelper = ViewHelper(self.request)
        template_values = viewhelper.get_navigation_options()
        template_values.update(viewhelper.get_menu_options())
        notification = 'Please fill your details and click Register to start your free trial'
        
        template_values.update({ 'app_notification': '{"app_notification": "'+notification+'", "app_notification_type": "app_tip"}'})
        subscriptionMgr = SubscriptionManager()
        
        #subscription data
        active_subscriptions = subscriptionMgr.get_all_active_subscriptions()
        
        template_values.update({'active_subscriptions': active_subscriptions})
                                   
        path = os.path.join(os.path.dirname(__file__), '../../templates', 'account.html')

        self.response.out.write(template.render(path, template_values))
Ejemplo n.º 2
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('/')