Ejemplo n.º 1
0
    def post(self):
        if not self.is_logged_in():
            self.redirect(LOGIN_PAGE_URL)
        else:
            customer = Customer.get_by_key_name(self.get_current_username())
            customer.first_name = self.get_argument('first_name')
            customer.last_name = self.get_argument('last_name')
            customer.timezone = self.get_argument('timezone')

            landline_key = self.get_argument('landline_key')
            landline = db.get(db.Key(landline_key))
            landline.number = self.get_argument('landline_number')

            mobile_key = self.get_argument('mobile_key')
            mobile = db.get(db.Key(mobile_key))
            mobile.number = self.get_argument('mobile_number')

            location_key = self.get_argument('location_key')
            location = db.get(db.Key(location_key))

            location.city = self.get_argument('city')
            location.country = self.get_argument('country')
            location.state_or_province = self.get_argument('state_or_province')
            location.area_or_suburb = self.get_argument('area_or_suburb')
            location.street_name = self.get_argument('street_name')
            location.zip_code = self.get_argument('zip_code')
            
            db.put([customer, mobile, landline, location])

            self.get()
Ejemplo n.º 2
0
 def post(self):
     if not self.is_logged_in():
         self.redirect(LOGIN_PAGE_URL)
     else:
         machine_id = self.get_argument('machine_id')
         timezone = self.get_argument('timezone')
         deactivation_entry_code = self.get_argument('deactivation_entry_code')
     
         customer = Customer.get_by_key_name(self.get_current_username())
         activation_credentials = ActivationCredentials.get_all_for_customer_and_machine_id(customer=customer, machine_id=machine_id)
         activation_credentials_list = []
         for credentials in activation_credentials:
             credentials_id = credentials.key().id()
             serial_number = self.get_argument('serial_number_ac_%d' % credentials_id)
             activation_code = self.get_argument('activation_code_ac_%d' % credentials_id)
             if serial_number == credentials.serial_number and activation_code == credentials.activation_code:
                 credentials.deactivation_code = self.get_argument('deactivation_code_ac_%d' % credentials_id)
                 credentials.deactivation_entry_code = deactivation_entry_code
                 credentials.timezone = timezone
                 credentials.when_deactivated = datetime.utcnow()
                 activation_credentials_list.append(credentials)
             else:
                 pass  # Error.
         db.put(activation_credentials_list)
         self.redirect('/dashboard')
Ejemplo n.º 3
0
 def post(self):
     machine_id = self.get_argument('machine_id')
     customer = Customer.get_by_key_name(session.get_current_username())
     credentials = ActivationCredentials.get_all_active_for_customer_and_machine_id(
         customer=customer,
         machine_id=machine_id)
     self.set_header('Content-Type', 'application/json')
     self.write(json.dumps(len(credentials) > 0))
Ejemplo n.º 4
0
 def get(self):
     if not self.is_logged_in():
         self.redirect(LOGIN_PAGE_URL)
     else:
         customer = Customer.get_by_key_name(self.get_current_username())
         subscriptions = []
         for order in customer.orders:
             subscriptions.append(order.subscription)
         self.render('unsubscribe.html', subscriptions=subscriptions)
Ejemplo n.º 5
0
 def post(self):
     if not self.is_logged_in():
         self.redirect(LOGIN_PAGE_URL)
     else:
         customer = Customer.get_by_key_name(self.get_current_username())
         if customer.is_password_correct(self.get_argument('old_password')):
             p = hash_password(self.get_argument('new_password'))
             customer.password_hash = p[0]
             customer.password_salt = p[1]
             customer.put()
         self.redirect('/dashboard')
Ejemplo n.º 6
0
 def post(self):
     email = self.get_argument('login-email')
     password = self.get_argument('login-password')
     customer = Customer.get_by_key_name(email)
     if customer:
         if customer.is_password_correct(password):
             self.do_login(email)
             self.redirect('/dashboard')
         else:
             self.redirect('/?error=login_failed')
     else:
         self.redirect('/?error=login_failed')
Ejemplo n.º 7
0
 def post(self):
     if not self.is_logged_in():
         self.redirect(LOGIN_PAGE_URL)
     else:
         machine_id = self.get_argument('machine_id')
         timezone = self.get_argument('timezone')
         deactivation_entry_code = self.get_argument('deactivation_entry_code')
     
         customer = Customer.get_by_key_name(self.get_current_username())
         activation_credentials = ActivationCredentials.get_all_active_for_customer_and_machine_id(customer=customer, machine_id=machine_id)
         self.render('deinstall_maths_english_input.html', 
             activation_credentials=activation_credentials,
             customer=customer,
             machine_id=machine_id,
             timezone=timezone,
             deactivation_entry_code=deactivation_entry_code)
Ejemplo n.º 8
0
 def get(self):
     if not self.is_logged_in():
         self.redirect(LOGIN_PAGE_URL)
     else:
         
         customer = Customer.get_by_key_name(self.get_current_username())
         if customer.has_active_activation_credentials():            
             from activation import generate_deactivation_entry_code
             from pytz.gae import pytz
             deactivation_entry_code = generate_deactivation_entry_code(timezone=customer.timezone)
             self.render('deinstall_maths_english.html', 
                 default_timezone=customer.timezone,
                 deactivation_entry_code=deactivation_entry_code,
                 timezones=pytz.all_timezones)
         else:
             self.render('deinstall_no_active_subscriptions.html')
Ejemplo n.º 9
0
    def post(self):
        from activation import generate_deactivation_entry_code

        timezone = self.get_argument('timezone')
        
        customer = Customer.get_by_key_name(self.get_current_username())
        customer.timezone = timezone
        customer.put()
        
        deactivation_entry_code = generate_deactivation_entry_code(timezone=timezone)

        self.set_header('Content-Type', 'application/json')
        self.write(json.dumps({
            'deactivationEntryCode': deactivation_entry_code,
            'timezone': timezone,
        }))
Ejemplo n.º 10
0
    def get(self):
        if not self.is_logged_in():
            self.redirect(LOGIN_PAGE_URL)
        else:
            from pytz.gae import pytz
        
            customer = Customer.get_by_key_name(self.get_current_username())

            landline = Phone.all().filter('profile = ', customer).filter('phone_type = ', 'landline').get()
            mobile = Phone.all().filter('profile = ', customer).filter('phone_type = ', 'mobile').get()

            self.render('profile.html', countries=COUNTRIES_TUPLE,
                landline=landline,
                mobile=mobile,
                customer=customer,
                location=customer.locations[0],
                default_timezone=customer.timezone,
                timezones=pytz.all_timezones)
Ejemplo n.º 11
0
    def post(self):
        # Get customer and create an invoice.
        customer = Customer.get_by_key_name(self.get_current_username())
        invoice = Invoice(customer=customer)
        invoice.put()

        # Now start processing subscription data.
        subscription_data = self.session['subscription-data']
        products = db.get([db.Key(key) for key in subscription_data.get('products')])
        period = subscription_data.get('period')
        subscription_period = SubscriptionPeriod.get_by_period(period)

        units = [product for product in products if 'product_keys' not in product.properties()]
        baskets = [product for product in products if 'product_keys' in product.properties()]

        activation_credentials_list = []
        orders = []
        for unit in units:
            subscription = Subscription.get_by_product_and_period(unit, period)

            order = Order(customer=customer, invoice=invoice, subscription=subscription)
            order.subscription_price = subscription.price
            order.subscription_general_sales_tax = subscription.general_sales_tax
            order.subscription_period_in_months = subscription.period_in_months
            order.subscription_free_period_in_months = subscription_period.free_period_in_months
            order.price = subscription.price + subscription.general_sales_tax
            order.subscription_currency = subscription.currency
            orders.append(order)
            order.put()

            unit_id = unit.key().id()
            activation_credentials = ActivationCredentials()
            activation_credentials.serial_number = self.get_argument('u_%d_serial_number' % unit_id)
            activation_credentials.machine_id = self.get_argument('u_%d_machine_id' % unit_id)
            activation_credentials.order = order
            activation_credentials.product = unit
            activation_credentials.customer = customer
            logging.info(activation_credentials)
            activation_credentials_list.append(activation_credentials)

        for basket in baskets:
            subscription = Subscription.get_by_product_and_period(basket, period)

            order = Order(customer=customer, invoice=invoice, subscription=subscription)
            order.subscription_price = subscription.price
            order.subscription_general_sales_tax = subscription.general_sales_tax
            order.subscription_period_in_months = subscription.period_in_months
            order.subscription_free_period_in_months = subscription_period.free_period_in_months
            order.price = subscription.price + subscription.general_sales_tax
            order.subscription_currency = subscription.currency
            orders.append(order)
            order.put()

            for unit in basket.products:
                basket_id = basket.key().id()
                unit_id = unit.key().id()

                activation_credentials = ActivationCredentials()
                activation_credentials.serial_number = self.get_argument('b_%d_u_%d_serial_number' % (basket_id, unit_id,))
                activation_credentials.machine_id = self.get_argument('b_%d_u_%d_machine_id' % (basket_id, unit_id,))
                activation_credentials.order = order
                activation_credentials.product = unit
                activation_credentials.customer = customer
                logging.info(activation_credentials)
                activation_credentials_list.append(activation_credentials)

        db.put(activation_credentials_list)
        
        invoice.total_price = sum([order.price for order in orders])
        invoice.currency = orders[0].subscription_currency
        invoice.put()
        
        self.session['activation-invoice-key'] = str(invoice.key())
        self.redirect('/activate/overview')
Ejemplo n.º 12
0
 def get(self):
     if not self.is_logged_in():
         self.redirect(LOGIN_PAGE_URL)
     else:
         customer = Customer.get_by_key_name(self.get_current_username())
         self.render('dashboard.html', customer=customer)